PDA

View Full Version : What's wrong with this?



swoll1980
May 1st, 2009, 02:06 AM
#include <stdio.h>
#include <stdlib.h>

int main(void) {
char *myenvvar=getenv("EDITOR");
printf("The editor environment variable is set to %s\n",myenvvar);
}

I get a syntax error, it's bash

doas777
May 1st, 2009, 02:11 AM
disregard. it compiled fine for me, but did give a warning that it was reaching the end of main without getting an exit signal. I just added exit(0); to the end of the block to make it go away.

lisati
May 1st, 2009, 02:11 AM
Compiles ok on my machine, and running the compiled file gives the following output:

The editor environment variable is set to (null)

EDIT: It's bash? Looks like a "C" program to me. I put the code in a file temp.c, made sure that build-essential was installed. typed in
gcc temp.c -o temp
./temp

swoll1980
May 1st, 2009, 02:18 AM
Compiles ok on my machine, and running the compiled file gives the following output:


EDIT: It's bash? Looks like a "C" program to me. I put the code in a file temp.c, made sure that build-essential was installed. typed in
gcc temp.c -o temp
./temp


OK thanks. after I compiled I tried to run it

./myenv.c
I forgot to drop the .c thanks for the help. I'm just learning this stuff. Sorry for wasting your time.

lisati
May 1st, 2009, 02:21 AM
OK thanks. after I compiled I tried to run it

./myenv.c
I forgot to drop the .c thanks for the help. I'm just learning this stuff. Sorry for wasting your time.

No, it wasn't a waste of time. I'm still learning too.

EDIT: It could be worse: With MS-DOS we'd have the choice between a .COM and an .EXE file; when producing an .EXE file we'd have a choice of MS-DOS only, a MS-DOS box within Windows, or one that uses the Windows GUI.

sekinto
May 1st, 2009, 02:30 AM
If that is C there should be a

return 0;
at the end of the main function.