Link to home
Start Free TrialLog in
Avatar of anders_01
anders_01

asked on

C programming in linux

i have gcc 2.8.0 and am trying to write just a small program that reads data from a file...it looks like this:

#include "/usr/include/stdio.h"
#include "/usr/include/stdlib.h"

int main(void)
{
 FILE *f;
 f = fopen("/tmp/test.tmp","r");


}


well, if i compile with:
gcc filename

the following errors occure:
parse error before *
f undeclared

i think i'm using regular ANSI C...isn't this supposed to work?
Avatar of imladris
imladris
Flag of Canada image

The only * I see is the one in the FILE *f line. So I'm guessing that the compiler didn't recognize the FILE as something useful. This, in turn, suggests that the stdio.h was not found or incorrect or something. Check that it is in the specified place (normally one writes: #include <stdio.h> and allows it to be resolved by standard system mechanisms), and that it contains something useful. FILE should be defined as a struct with a bunch of file information in it.

you should include the directories in your Options->Directories from the menu in the IDE... The you should do this...

#include <stdio.h>

for opening a file you should do this...

f = fopen("C:\\tmp\\test.tmp","r");

and so on... Hope this help[s....

-Viktor
--Ivanov
Viktor, I recommended the same thing w.r.t. stdio.h. While that is the normal way of doing it, the full filepath between double quotes is also legal and should work, if the files are there.

It is definitely not true that filepath elements need to be separated by "\\". That is the case in DOS, since DOS decided on the demented paradigm of using a backslash for separating elements. However Unix, and thus Linux, use a forward slash.
This question is specifically in reference to Linux. Please be aware of elements that are DOS specific.

Avatar of anders_01
anders_01

ASKER

well, this is linux...so i have to use forward slashes.
my include dirs are correct too...

i read the gcc man page and figured out that
gcc +x c++ file.c -ansi
was a better commad line...


well, someone who knows about a good IDE for linux with inline help and stuff...?? i used to use the Borland IDE for DOS....



anders 01 try the WPE  it looks just like Borland for dos.
http://www.linuxos.org/Lprogram.html   scroll down this page
a little there are a few other IDEs for linux.
ASKER CERTIFIED SOLUTION
Avatar of HalldorG
HalldorG
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that IDE seems to be one that i was looking for, thanks!