feof Programming Software Development by jazzz Hi, I need to read all the records in a file till the end and print it to an outputfile. So I used feof() - while(feof(fp_infile) !=0) { fread(xxxx); fread(xxxx); fprintf(fp_outfile, XXXXX); } But this is not giving me any output i.e, the output file is empty. Can anyone help??? Is the usage of feof() wrong?? jazz Re: feof Programming Software Development by Ancient Dragon 1. do not use feof(). 2. your program is mixing binary file read with text … feof() and do {for a} while - or do {...} until? Programming Software Development by ThomsonGB … am seeing the last line *TWICE* in my output, so feof must trigger // from the error caused by reading past the… this file since it changes and it's fun while (!feof(infile)) { fgets(LineBuffer, BUFFERSIZE, infile); // lines will be truncated if… Re: feof() and do {for a} while - or do {...} until? Programming Software Development by Narue …* in my output[/QUOTE] This is precisely the reason why feof() shouldn't be used as the only loop condition. It… Re: feof() and do {for a} while - or do {...} until? Programming Software Development by rubberman … loop internals to this and see what happens: [code] while (!feof(infile)) { if (fgets(LineBuffer, BUFFERSIZE, infile) != NULL) { printf("%s… Re: feof() and do {for a} while - or do {...} until? Programming Software Development by ThomsonGB ////////////////////////////////////////////////////////////////////////////////// // Solution: feof() depends on an error to occur. So to avoid the … feof problem Programming Software Development by tubby123 …/Desktop/write.txt","r"); while(1) { if(feof(fp)) break; fscanf (fp, "%d", &i); printf… Re: feof() and do {for a} while - or do {...} until? Programming Software Development by rubberman Ah Narue! You beat me to the post, again! :-) Seems like we are giving more or less the same advice. Re: feof() and do {for a} while - or do {...} until? Programming Software Development by ThomsonGB Thanks everyone who answered this! I guess I figured it out to, so we have a consensus and a good lesson learned. Good luck to You all in the new years. 73 -Grace NNNN z Problem with !feof Programming Software Development by jcmoney1010 … times, in different orders. I tried to add a `while(!feof())` function, but when I did this the program crashes as…;*counter;i++), but this gives me the bad results. while(!feof(read)){ fscanf(read,"%s %s %s %s",friends… Help with !feof Programming Software Development by watery87 …) perror ("Error opening file 'Countries.txt' !"); else { while ( !feof (pFile) ) { char* aLine = get_line (buffer, Line_Char_Buffer_Size, pFile); if (aLine != NULL… Re: feof problem Programming Software Development by Ancient Dragon The loop is wrong ~~~ while( fscanf(...) > 0) { printf ("Integer read = [%d]\n",i); } ~~~ Re: Problem with !feof Programming Software Development by Ancient Dragon line 288: Where is the memory being allocated for the members of that structure? All I see is unallocated pointers, which is why your program crashes when it tries to execute that scanf(). scanf() doesn't allocate memory, you have to do that yourself before calling scanf(). One way to fix the problem is to use temp buffers for scanf() then … Re: Help with !feof Programming Software Development by Adak Use while((fgets(bufferName, sizeof(bufferName), filePointerName)) != NULL) { instead. Testing for the end of the file has become quite unpopular (and deservedly so), for just this reason (among others). Don't use it. Re: Help with !feof Programming Software Development by watery87 Hi, I tried the method u suggested. However it doesnt even display everything, it instead omits it from displaying. This is what i wrote [code] void readData () { FILE * pFile; NoOfRecordsRead = 0; char buffer [Line_Char_Buffer_Size]; pFile = fopen (INPUT_FILE_NAME , "r"); if (pFile == NULL) perror ("Error opening … Re: Help with !feof Programming Software Development by Ancient Dragon What does get_line() do? Does that function also read a line from the file? If it does then your program is reading two lines at a time before doing anything with them. [code] void readData () { FILE * pFile; NoOfRecordsRead = 0; char buffer [Line_Char_Buffer_Size]; pFile = fopen (INPUT_FILE_NAME , "r");… Re: Help with !feof Programming Software Development by zerocool21 u have read line in c !! readline will read a line from the terminal and return it, using prompt as a prompt. If prompt is null, no prompt is issued. Re: Extra Data when reading from files Programming Software Development by Salem feof() doesn't do what you think it should do. [url]…/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351[/url] feof() can only return true AFTER some other operation (say fread… Re: Array help in c Programming Software Development by Aia feof() is a poor choice to control a loop since feof() is true after the file EOF is read and not when EOF is reached. Meaning that while(!) will loop one more time before it knows it shouldn't. Segmentation fault when reading from file Programming Software Development by hari.sarvothama …(1) { fscanf(fp2,"%s",a); if(feof(fp2)) break; strcpy(o_tbl[count].opco,a); fscanf(fp2… while(1) { fscanf(fp,"%s",a); if(feof(fp)) break; if(strcmp(a,"START")!=0) {…strcpy(a,b); fscanf(fp,"%s",b); if(feof(fp)) break; obco=check(a,b); } fprintf(fp1,&… Need help with external sort algorithm Programming Software Development by Troilk …,FTS); fputs(temp1,A); tmp++; } } while(!feof(FTS)) //all other numbers write to second temp file… continue iterations while((iterCon && !feof(A) && !feof(B)) || (once && iterCon…0; else break; iterB++; } } } while(!feof(A)) //if one of files was larger than… Request help to fix my program Programming Software Development by Anbuvengeance …fopen("student.csv", "rt"); while(!feof(inputFile)) { fscanf(inputFile,"%[^\n]\n",student);…fopen("instructor.csv", "rt"); while(!feof(inputFile)) { fscanf(inputFile,"%[^\n]\n",instructor);… I tried and still failed. Programming Software Development by yasaswyg … spM1); if(feof(spM1)) recM1 = sentinel; if(feof(spM2)) recM2 = sentinel; while(!feof(spM1)|| !feof(spM2)) {…char buffer[100]; char *feof; feof = fgets(buffer, sizeof(buffer), textFile); if(feof) sscanf(buffer, "%… SCZ (Simple Compression Zip) Decompression of Binary data Programming Software Development by Haider85 …chksum = 0; szi = 0; buffer0_hd = 0; buffer0_tl = 0; while ((!feof(infile)) && (szi < buflen)) { scz_add_item( &buffer0_hd, &… } fprintf(outfile,"%c", chksum); sz2++; if (feof(infile)) fprintf(outfile,"]"); /* Place no-continuation marker. … Coding Help for OP Database Programming Web Development by MadMaddie ….</P>\n"; exit; } else { while (!feof($file) ) { $line = fgets($file, 1024); if (….</P>\n"; exit; } else { while (!feof($file) ) { $line = fgets($file, 1024); if (….</P>\n"; exit; } else { while (!feof($file) ) { $line = fgets($file, 1024); if (… Re: I tried and still failed. Programming Software Development by wildgoose …, INV_REC* txt) { char buffer[100]; char *feof; feof = fgets(buffer, sizeof(buffer), textFile); if(feof) sscanf(buffer, "%s %s %d"…;, txt->partNo, txt->partName, &txt->qtyonHand); return feof; } File Handling - Adding Programming Software Development by soban … &ID, Name, &Gender, &Amount); if(feof(infile)) break; if(strcmp(Target, Name) != 0) fprintf… OF THE PHILIPPINES" << endl; while(!feof(infile)) { fscanf(infile, "%i %s %c…quot;; cin >> Target; while(!found) { while(!feof(infile)) { fscanf(infile, "%i %s %c … Re: Segmentation fault when reading from file Programming Software Development by Adak … the same name - for heaven's sake. :( Also, you use feof(), which doesn't work as you'd expect. Better to… Need Help combining programs into one Programming Software Development by gallantmon1 …EOF) break; else { if(doc==';') { while(!feof(input)) { doc=fgetc(input); if(doc=='\n…EOF) break; else { if(doc==';') { while(!feof(src)) { doc=fgetc(src); if(doc=='\n… Re: Need help with external sort algorithm Programming Software Development by nezachem Pascal and C deetct end-of-file in a different way. Not getting into details, a [ICODE]while(!feof())[/ICODE] idiom is unsafe in C. A correct way to read a file is [ICODE]while(fgets() != 0)[/ICODE]