mah pix

Friday, October 10, 2008

Final Question

Since not all MCS 213 students can try DEBUG commands because of the technical problems of our computers, search now any Turbo C program with assembly codes in it and run this in your PC. Check the result of your running C program.If the program produces the expected output, copy the Turbo C codes into your post and its result. YOu may do this by pressing Print Screen on your keyboard for the result of your program then, switch to Paint Brush and Paste. Resize the window and copy this to your post.









#include
#include
#include


/********************************************************



* my_strchr -- Finds a character in a string. *



* Duplicate of a standard library function, *



* put here for illustrative purposes *



* *



* Parameters *



* string_ptr -- String to look through. *



* find -- Character to find. *



* *



* Returns *



* pointer to 1st occurrence of character *



* in string or NULL for error. * ********************************************************/



char *my_strchr(char * string_ptr, char find)



{



while (*string_ptr != find) {



/* Check for end */



if (*string_ptr == '\0')



return (NULL); /* not found */



++string_ptr; } return (string_ptr); /* Found */



}



int main()



{



char line[80]; /* The input line */



char *first_ptr; /* pointer to the first name */



char *last_ptr; /* pointer to the last name */



fgets(line, sizeof(line), stdin);



/* Get rid of trailing newline */



line[strlen(line)-1] = '\0';



last_ptr = line; /* last name is at beginning of line */



first_ptr = my_strchr(line, '/'); /* Find slash */



/* Check for an error */



if (first_ptr == NULL)



{



fprintf(stderr,



"Error: Unable to find slash in %s\n", line);



exit (8);



}



*first_ptr = '\0'; /* Zero out the slash */



++first_ptr; /* Move to first character of name */



printf("First:%s Last:%s\n", first_ptr, last_ptr);



return (0);



}










No comments: