C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 22nd, 2003, 05:17 AM
Jadams Jadams is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Scotland
Posts: 185 Jadams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 40 m 14 sec
Reputation Power: 6
Reading files using Fgets, strange errors on compile.

Hi all,

I am trying to write a program to open a file, read the file line by line, and display the contents after the = sign on screen.

I am having problems, however, here is the code I am using:
#include <stdio.h>
#include <strings.h>

main()

{
char word[50];
char *pntr

/* Get pointer */
FILE *input_file_pointer;

/* Open file */
input_file_pointer = fopen("clist.cfg","r");

/* if file is not present then stop */
if (input_file_pointer == NULL)
{
printf("Fail\n");
return 0;

}
else
/* read in line by line and print on screen what is after the = sign */
while (fgets(word, 50, input_file_pointer) != EOF)
{
pntr = strchr(word, '=');
pntr++;
printf("%s", pntr);
}
fclose(input_file_pointer);
}

when I compile the program I get these errors:

syntax error before 'FILE'
new.c:14 'input_file_pointer' undeclared (first use in this function)
new.c:25 warning:comparison between pointer and integer
new.c:27 'pntr' undeclared (first use in this function)

Now I can open the file, and close the file. Somehow adding the while loop with fgets messes things up a little, its prolly quite easy but its starting to bug the hell outta me.

Any help is greatly appreciated guys.

Reply With Quote
  #2  
Old June 22nd, 2003, 07:38 AM
BigBadBob BigBadBob is offline
status unknown
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 262 BigBadBob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
> char *pntr

You need to add a semi-colon to the end of that line. The clue is here:

> syntax error before 'FILE'


> #include <strings.h>

shouldn't this be <string.h>?

Last edited by BigBadBob : June 22nd, 2003 at 07:42 AM.

Reply With Quote
  #3  
Old June 22nd, 2003, 08:23 AM
Jadams Jadams is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Scotland
Posts: 185 Jadams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 40 m 14 sec
Reputation Power: 6
Ok thanks for that, those were silly little things as I thought.

Reword but still get some problems when compiling, these are two warnings. Anyone care to explain:

new.c
new.c(25) : warning C4047: '!=' : 'char *' differs in levels of indirection from
'const int '
new.c(32) : warning C4715: 'main' : not all control paths return a value

oh and I get an error when running this. Think its something to do with when I reach the end of the file.

using visual studio cl compiler this time for quickness, last time I used cc.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Reading files using Fgets, strange errors on compile.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT