Friday, July 31, 2009

HELP me about file proccesing in TurboC?

heres my program...





#include%26lt;stdio.h%26gt;


void main(void)


{


FILE *inputf;


char filename[40];


int c;





printf("Input name of the text file");


fgetc(filename);





if (inputf = fopen(filename, "r") == NULL)


{


printf("ERROR: %s cannot be opened.\n", filename);


exit(1);


}


while ((c = fgetc(inputf)) != EOF)


fputc(c, stdout);


fclose(inputf);


}





I have a problem with "fgetc(filename);" I know that its wrong but I don't know how to apply it in my program and its a requirement to use it in my program, to use it as character input.. so please someone recode this.. I'm begging and I know its easy to you guys..


thank you..

HELP me about file proccesing in TurboC?
your fclose() should be outside (below) your while loop. Otherwise, you only read 1 character, close the file, then try to read from it.


No comments:

Post a Comment