473,378 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

fgets function

10
Hello all,
iam using fgets() function to read from the stream,

Expand|Select|Wrap|Line Numbers
  1. pFile = fopen ("al.odl","r");
  2. while (!feof(pFile))
  3. {
  4. fgets(data, 80,pFile);    
  5.  printf("%s", data);
  6. }
  7. fclose(pFile);
it should give me
Expand|Select|Wrap|Line Numbers
  1. al : Object
  2. {
  3.     initialize : Expr()
  4.     {
  5.         @Println("al loaded");
  6.     }
  7. }
but it is giving one extra brace at end.
like
Expand|Select|Wrap|Line Numbers
  1. al : Object
  2. {
  3.     initialize : Expr()
  4.     {
  5.         @Println("al loaded");
  6.     }
  7. }
  8. }
please can anyone solve this problem it may look very simple but iam not understanding why extra brace } is coming, please help me.
Nov 29 '07 #1
5 1349
oler1s
671 Expert 512MB
I'll give you the answer, but I want to see if you are able to understand intuitively what the mistake is. (If not, I'll have to modify my explanation a bit).

First, post what you think feof does. Now, take a look the documentation for feof. What do you see is the problem here? (Please do make an attempt to figure this out on your own. Although I'll clarify anyway later on.)
Nov 29 '07 #2
vin029
10
thank you for reply,
please tell me , if u have understood my mistake iam eagerly ,
searching for the solution any how i tried myself also if u can tell it
will be a great help me to me.
Nov 29 '07 #3
oler1s
671 Expert 512MB
I don't think you understand. I want YOU to post the answers to my questions. At least make an attempt to answer them.
Nov 29 '07 #4
vin029
10
hello sir,
i really tried i think i have done mistake with clearerr() function but even though
iam including that iam not reaching the exact, please really i have tried that one , please correct my code and show me that exactly where i went wrong then it will be a very great help to me . because u people r very expert.
please please help me.
Nov 30 '07 #5
vin029
10
hello ,
i got the answer i understood the use of feof
i modified the code as
Expand|Select|Wrap|Line Numbers
  1. while(1)
  2. {
  3. fgets(str,80,pFile);
  4. if(feof(pFile))
  5. break;
  6. printf("%s",str);
  7. }
and also no need to use the feof() instead

Expand|Select|Wrap|Line Numbers
  1. while(fgets(str,80,pFile)!=null)
  2. {
  3. }
this also works.
Nov 30 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
10
by: Stuart Anderson | last post by:
I am looking to use Ken Stephenson's CirclePack program (http://www.math.utk.edu/~kens/) with some tiling programs written by Cannon, Floyd, Parry. The programs I want to use are subdivide.c...
20
by: Paul D. Boyle | last post by:
Hi all, There was a recent thread in this group which talked about the shortcomings of fgets(). I decided to try my hand at writing a replacement for fgets() using fgetc() and realloc() to read...
16
by: DJP | last post by:
Hi, I need to read a file programmatically until end of file. My logic is as follows: while(!feof(Fp)) { fgets(readLine,10000,Fp);
20
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The...
35
by: David Mathog | last post by:
Every so often one of my fgets() based programs encounters an input file containing embedded nulls. fgets is happy to read these but the embedded nulls subsequently cause problems elsewhere in...
32
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where...
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
26
by: Bill Cunningham | last post by:
I was talking with someone about fgets and he said that fgets puts the \n in a string but not \0. I decided to test this assumption because my documentation didn't say if fgets put \0 after a...
14
by: subramanian100in | last post by:
Suppose fgets is used to read a line of input. char str; fgets(str, sizeof(str), stdin); After reading some characters on the same line, if end-of-file is encountered, will fgets return the 'str'...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.