Solved

C programming in linux

Posted on 1999-01-22
7
194 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
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
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 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.

864 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

24 Experts available now in Live!

Get 1:1 Help Now