Here is my problem:
Write a C program that will read and display every second character in the file named test.dat.
Here is the cod I have so far:
I was wondering can I make the test.dat file at the beginning of the program and then access it right after that? Also does anyone have any ideas on how to read the 2nd character? I was trying to spell out a message once I got it to work. I was thinking a FOR loop but not sure how to make it work. Can I increment by 2 and if so how? Thanks for helping me out guys. Also how do I get this to indent so the code is easier to read? It looks fine in the message box.Code:#include <stdio.h> int main() { FILE *outfile; char data[40] = "kTjHdIjSo kInSg xAc rCv hPhRyOmGqRaAeM"; outfile = fopen("test.dat","w"); if (outfile == NULL) { printf("\nFailed to open the file.\n"); } fprintf(outfile,"%-40s\n",data[40]); fclose(outfile); FILE *infile; infile = fopen("test.dat","r"); if (infile == NULL) { printf("\nFailed to open the file.\n"); } while (fscanf(infile, "%s",data) !=EOF) printf("%-40s\n",data); fclose(infile); return 0; }



LinkBack URL
About LinkBacks


