The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to make a line BLINKING in output and also how to increase font size in output mail2sant Shell Programming and Scripting 3 04-14-2008 04:30 AM
Why I don't get any output? Sharmin High Level Programming 6 09-17-2006 09:34 AM
awk output? kion Shell Programming and Scripting 6 02-11-2005 08:56 PM
FTP Output lindeng UNIX for Dummies Questions & Answers 9 02-10-2004 07:18 PM
Deleting a File with an Erroneous Period PLF UNIX for Dummies Questions & Answers 3 08-08-2001 11:04 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-11-2007
Registered User
 

Join Date: Sep 2006
Posts: 55
erroneous output

#include<stdio.h>
int main ()
{
FILE* f_read;
FILE* f_write;
char *string[80];
f_read=fopen("file1","r");

while(!feof(f_read));
{
fscanf(f_read,"%s",string);
fprintf(stdout,"%s\n",string);
}

return 0;
}


INPUT FILE
___________
manu
jilu
ruta

OUTPUT
-----------
manu
jilu
ruta
ruta

why the last line is being read two times
Reply With Quote
Forum Sponsor
  #2  
Old 07-11-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
You are not error checking the return from your fscanf()
Reply With Quote
  #3  
Old 07-11-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,327
Quote:
Originally Posted by bishweshwar View Post
why the last line is being read two times
It isn't being read twice, it is being written(printed) twice. As porter has suggested, check the return value on your fscanf and exit if it is EOF.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0