I need to be able to display every other character in my test.dat file. The test.dat file contains the number 123456.
What is the best way to go about this?
#include<stdio.h>
int main()
{
int ch;
long int offset, last;
FILE *inFile;
inFile = fopen("test.dat","r");
if (inFile == NULL)
{
printf("\nFailed to open the test.dat file. \n");
exit(1);
}
fseek(inFile,0L,SEEK_END);
last = ftell(inFile);
for(offset = 0; offset <= last ; ++offset)
{
fseek(inFile, +offset, SEEK_SET);
ch = getc(inFile);
switch(ch)
{
case '\n': printf("LF : ");
break;
case EOF : printf("EOF: ");
break;
default : printf("%c : ",ch);
}
}
fclose(inFile);
return 0;
}