473,387 Members | 1,700 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,387 software developers and data experts.

Problem opening a file in C

Dan
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>
Nov 13 '05 #1
4 3166
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?


Nov 13 '05 #2
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
Nov 13 '05 #3
goose wrote:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message news:<3F**************@jpl.nasa.gov>...
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.

Nov 13 '05 #4
Dan
That fixed it. Thank you very much for your help.

"Artie Gold" <ar*******@austin.rr.com> wrote in message
news:3F**************@austin.rr.com...
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

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Graham Taylor | last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it here also, as I think it might be the webserver which is causing my problem. --------- I have an Access 2003 database...
1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
5
by: John Morgan | last post by:
I am using the following link to download a file of about 50k <a target= "_blank" href="http://www.bsecs.org.uk/ExecDocs/documentStore/elfridaWord.doc">open file</a> If I save the file to...
8
by: beginner10 | last post by:
Hello! Can anyone help me? This code doesnt work. Where is the problem? Inside the files mata and matb there is (should be) 10*10 matrix. It should count a sum to new matrix. It does not work....
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
0
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual...
0
by: nt91rx78 | last post by:
Our college changes 18 weeks semester to 16 semester, so our CS professor cannot finish teaching the last important chapter which is related with my problw\em. This is program C problem Anyone...
5
by: GeekBoy | last post by:
Thanks for the help obnoxious. Reading in the rest of the line with "getline" worked great and now the averages work. Now for the new problem. Program on first run works flawlessly. Next runs...
3
by: =?iso-8859-9?B?RGlu52F5IEFr5/ZyZW4=?= | last post by:
When I execute the following code #include <stdio.h> #include <stdlib.h> int main(void) { FILE *bmp; bmp = fopen("deneme.bmp","w"); fputc(10,bmp);
1
by: Sanjeeva K kanakam | last post by:
Hi all, I am developing one application. In that i have created on report file which contains tables, titles and tree view list also by using HTML tags. I am opening this file in my application it...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.