Solved

C programming in linux

Posted on 1999-01-22
7
193 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:anders_01
7 Comments
 
LVL 16

Expert Comment

by:imladris
Comment Utility
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.

0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
0
 
LVL 16

Expert Comment

by:imladris
Comment Utility
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.

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:anders_01
Comment Utility
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....



0
 

Expert Comment

by:strmtrpr
Comment Utility
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.
0
 
LVL 7

Accepted Solution

by:
HalldorG earned 20 total points
Comment Utility

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

int main(void)
   {  
 FILE * tmp_file;
 char * tmp_filename;
 tmp_filename = "/tmp/file1";
 tmp_file = fopen (tmp_filename, "r");
 }


compile with
gcc filopen.c -o fileopen
0
 

Author Comment

by:anders_01
Comment Utility
that IDE seems to be one that i was looking for, thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c language help - file paths 7 113
Where is my core dump file in Ubuntu? 12 424
pgpool-II on Ubuntu 14.04... ARGH! 5 807
valid enum? 6 67
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now