Solved

C programming in linux

Posted on 1999-01-22
7
198 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

829 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