erroneous output


 
Thread Tools Search this Thread
Top Forums Programming erroneous output
# 1  
Old 07-11-2007
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
# 2  
Old 07-11-2007
You are not error checking the return from your fscanf()
# 3  
Old 07-11-2007
Quote:
Originally Posted by bishweshwar
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Erroneous file concatenation.

I have more than one files in a directory , namely GLOW_OUT.txt FIELD_OUT.txt BASE_OUT.txt ... SHOW_OUT.txt What I wanted to do is to I am working in Korn Shell What I did was : for file in <directory_name>/*.* ;do cat $file | grep -v '^$' >> temp_file rm $file done ... (7 Replies)
Discussion started by: kumarjt
7 Replies

2. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

3. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

how to make a line BLINKING in output and also how to increase font size in output

how to make a line BLINKING in output and also how to increase font size in output suppose in run a.sh script inside echo "hello world " i want that this should blink in the output and also the font size of hello world should be big .. could you please help me out in this (3 Replies)
Discussion started by: mail2sant
3 Replies

6. UNIX for Dummies Questions & Answers

Deleting a File with an Erroneous Period

Hi - I am new to the Unix environment and have encountered a problem I can't resolve. I inadvertently created a data file with a period/dot at the end of the word 'dat', I.e. filename.dat. and can't remove it using the 'rm' command. In attempting to do so, I receive a message reading that the... (3 Replies)
Discussion started by: PLF
3 Replies
Login or Register to Ask a Question