Hi all!
During my OS assignment, I'm having a little problem regarding filing. The problem is that I'm to read each line in a separate array and after that perform further operations. I've initially read the entire file in a char array and after that I intend to split it up accordingly. The file is in the following format:
P1 0
12 2 21 2 12 32 18
P2 9
13 17 3 21 45 67 21
(and so on)
I've written the following code:
But when I output the supposedly initial charaters from the array s[i] (which contains the entire file supposedly), it outputs 4,5,7,6. (It should output the first line of the file, i.e P1 (a tab) 0)Code:(Variables definitions and all) f=fopen ("umer.txt","r"); if (!f) printf ("Could not open the file.\n"); while (fgets (s,'\n',f)!=NULL) { if (s[i] == 'P') { processes++; } printf ("%s", s); } printf ("processes are: %d\n", processes); printf ("\n"); fclose(f); while (s[i]!='\n') { printf ("char is: %c\n", s[i]); i++; printf ("-%d-", i); }
What should I do? Any help would be highly appreciated.
Thanks.



LinkBack URL
About LinkBacks


