Solved

C programming in linux

Posted on 1999-01-22
7
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 1258327
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
ID: 1258328
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
ID: 1258329
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:anders_01
ID: 1258330
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
ID: 1258331
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
ID: 1258332

#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
ID: 1258333
that IDE seems to be one that i was looking for, thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

752 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