Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Problem opening a file in C

Reply
Thread Tools

Problem opening a file in C

 
 
Dan
Guest
Posts: n/a
 
      07-29-2003
Greetings:

I was trying to read in a file using C, and I got a strange error, compling
it in gcc for Solaris:

Code segment:
#include <stdio.h>
#include <stdlib.h>
.
.
.

FILE *file;
char temp[10];
file = fopen("filelist.txt", "r");
int i = 0;
.
.
.

End Code segment

I got a message saying something along the lines of '(87) parse error before
int'. Anybody have any ideas as to what could be wrong?

Thanks,
Daniel



 
Reply With Quote
 
 
 
 
E. Robert Tisdale
Guest
Posts: n/a
 
      07-29-2003
Dan wrote:

> I was trying to read in a file using C, and I got a strange error, compling
> it in gcc for Solaris:
>
> Code segment:
> #include <stdio.h>
> #include <stdlib.h>
> .
> .
> .
>
> char temp[10];


FILE* file = fopen("filelist.txt", "r");

> int i = 0;
> .
> .
> .
>
> End Code segment
>
> I got a message saying something along the lines of '(87) parse error before
> int'. Anybody have any ideas as to what could be wrong?


 
Reply With Quote
 
 
 
 
Martijn
Guest
Posts: n/a
 
      07-29-2003
Artie Gold wrote:
> Dan wrote:
>> FILE *file;
>> char temp[10];
>> file = fopen("filelist.txt", "r");
>> int i = 0;

>
> In C89, which your compiler most likely implements, all declarations
> must be at the beginning of a block; C99 (and C++) do not have that
> restriction[1].
>
> You could, for example, move the declaration of `i' above the call to
> fopen().


Or you could make a new, unnamed, segment with a new scope, which will cause
i to be a temporary variable available only to that segment:

file = fopen(szFileName, "r");
{
int i = 0;

// the rest of the segment here
}

--
Martijn Haak
http://www.serenceconcepts.nl


 
Reply With Quote
 
Steve Zimmerman
Guest
Posts: n/a
 
      07-29-2003
goose wrote:

> "E. Robert Tisdale" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
>
>>Dan wrote:
>>
>>
>>>I was trying to read in a file using C, and I got a strange error, compling
>>>it in gcc for Solaris:
>>>
>>>Code segment:
>>>#include <stdio.h>
>>>#include <stdlib.h>
>>> .
>>> .
>>> .
>>>
>>> char temp[10];
>>>

>> FILE* file = fopen("filelist.txt", "r");
>>
>>
>>> int i = 0;
>>> .
>>> .
>>> .
>>>
>>>End Code segment
>>>
>>>I got a message saying something along the lines of '(87) parse error before
>>>int'. Anybody have any ideas as to what could be wrong?
>>>

>
> ?????
> could you be less cryptic ? what exactly is that supposed to solve ?
> the OP will have *NO* idea why that will work, and he will repost
> about the other errors in his code that are similar.
>
> goose,
> helpfull today ?
>


Please post more of your program before the int part that the
compiler complained about. I tried the file open and it
compiled fine for me.

 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      07-29-2003
That fixed it. Thank you very much for your help.

"Artie Gold" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dan wrote:
> > Greetings:
> >
> > I was trying to read in a file using C, and I got a strange error,

compling
> > it in gcc for Solaris:
> >
> > Code segment:
> > #include <stdio.h>
> > #include <stdlib.h>
> > .
> > .
> > .
> >
> > FILE *file;
> > char temp[10];
> > file = fopen("filelist.txt", "r");
> > int i = 0;
> > .
> > .
> > .
> >
> > End Code segment
> >
> > I got a message saying something along the lines of '(87) parse error

before
> > int'. Anybody have any ideas as to what could be wrong?
> >

>
> In C89, which your compiler most likely implements, all declarations
> must be at the beginning of a block; C99 (and C++) do not have that
> restriction[1].
>
> You could, for example, move the declaration of `i' above the call to
> fopen().
>
> HTH,
> --ag
>
> [1] IMHO, to their detriment
>
> --
> Artie Gold -- Austin, Texas
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with opening Excel after opening Excel inside Microsoft Internet Controls fniles ASP General 0 04-26-2009 09:39 PM
Anyone resolved links opening blank page? or box opening in Outlook 2000? S.Rodgers Firefox 13 12-16-2005 03:07 PM
Word file not opening from Adm -My recent docs but opening from file menu of Word Thaqalain Computer Support 0 06-30-2005 02:20 AM
opening file - file does not exist but no error ben C++ 10 02-25-2004 09:12 PM
need some help with dial box opening when opening a folder John Computer Information 0 11-13-2003 08:38 PM



Advertisments