Hi,
Could someone pls tell me what I am doing wrong in the code below.
I'm trying to read two strings into two variables.
When I printf in the function ProcessString, I get what I am looking for. However when I printf first and second in
main, I don't get those strings.
I'm I calling ProcessString the wrong way from main?
Thanks.
Code:#include <stdio.h> void ProcessString(FILE *infile, char *fval, char *sval) { `int i = 0; int ch; char localfval[1024]; char localsval[1024]; if ((ch = fgetc(infile)) != EOF) { while (ch != 'X') { localfval[i++] = ch; } localfval[--i] = '\0'; i = 0; while (ch != 'Y') { localsval[i++] = ch; } localsval[--i] = '\0'; } fval = localfval; sval = localsval; printf("%s, %s\n", localfval, localsval); } int main() { FILE *infile; char *first; char *second; if (infile = fopen("filename.txt", "r") == NULL) exit(0); ProcessString(infile, first, second); printf("The first string is %s\n", first); printf("The second string is %s\n", second); fclose(infile); return (1) }



LinkBack URL
About LinkBacks


