I am reading a tutorial on C and the first code exercise gives me the very famous hello world code
#include < stdio.h>
void main()
{
printf("\nHello World\n");
}
i wrote mine like..
#include < stdio.h>
void main()
{
printf("\nHello World\n");
}
does it have to have the spaces before printf? i typed it out in gedit in ubuntu saved it as hello.c then went to the terminal and did a gcc hello.c and got the error
hello.c:1:20: error: stdio.h: No such file or directory
hello.c: In function ‘main’:
hello.c:5: warning: incompatible implicit declaration of built-in function ‘printf’
hello.c:4: warning: return type of ‘main’ is not ‘int’
im guessing that i am not compiling it right, or useing a diffrent version of linux then the tutorial is for? it is suppose to create a executable file called a.out? i thought executables were .exe .. i dunno any help would be appriciated, thanks
C compiling question
- Still_Learning
- Fame ! Where are the chicks?!
- Posts: 1040
- Joined: 11 Jun 2008, 16:00
- 15
- Location: Trigger City
- floodhound2
- ∑lectronic counselor
- Posts: 2117
- Joined: 03 Sep 2006, 16:00
- 17
- Location: 127.0.0.1
- Contact:
- Still_Learning
- Fame ! Where are the chicks?!
- Posts: 1040
- Joined: 11 Jun 2008, 16:00
- 15
- Location: Trigger City
ok so at the beginning of the code it is calling for the file stdio.h, a .h file is pretty much a macro file that you use in the header to be called on later then correct? i guess i need to create a whole new directory for c code would be the best huh, i just stored it in my documents folder and tried to compile it in terminal , i have gcc installed so i thought it would automatically compile it lol
btw; where is a good place to get clean .h files? or what is a good editor for ubuntu that allready has them included, thanks
btw; where is a good place to get clean .h files? or what is a good editor for ubuntu that allready has them included, thanks
- floodhound2
- ∑lectronic counselor
- Posts: 2117
- Joined: 03 Sep 2006, 16:00
- 17
- Location: 127.0.0.1
- Contact:
Well if you are asking me I can only say that I use header files that came with my compiler (DEV C by bloodshed). Or you make your own header files.
_You can depending on the compiler just make a directory and list it in the source code.
example:
_Something like that. Again I am a electronics "C" programmer using windows, so some of my examples may or may not directly apply.
_You can depending on the compiler just make a directory and list it in the source code.
example:
Code: Select all
#include < c:/mydoc/stdio.h>
- Still_Learning
- Fame ! Where are the chicks?!
- Posts: 1040
- Joined: 11 Jun 2008, 16:00
- 15
- Location: Trigger City
Is there a major diffrence between C and C++? which one is the best to start learning with?
I checked out Dev C by Bloodshed and did not really see a linux version, Would Emacs work for compiling C or is it only for Lisp? (sounds like a question for G-Brain)
humm.. maybe i will try compiling it on my windows machine with Dev C, sounds like a good compiler, Also do you have any good links for a quick reference manual for variables and function commands and such? thanks Floodhound
also btw i just installed Dev C on windows XP and got the error: There does not seems to be a GNU make file in PATH or in Dev-C++ Bins path, Please make sure that you have GNU make and adjust bin setting or system PATH evironment variable and that make setting in Compiler option contains correct filename, other wise i will not be able to compile anything"
i also just tried to compile the same code above in Dev C and got the error "huh? why in the world are you trying to compile and empty project "
I checked out Dev C by Bloodshed and did not really see a linux version, Would Emacs work for compiling C or is it only for Lisp? (sounds like a question for G-Brain)
humm.. maybe i will try compiling it on my windows machine with Dev C, sounds like a good compiler, Also do you have any good links for a quick reference manual for variables and function commands and such? thanks Floodhound
also btw i just installed Dev C on windows XP and got the error: There does not seems to be a GNU make file in PATH or in Dev-C++ Bins path, Please make sure that you have GNU make and adjust bin setting or system PATH evironment variable and that make setting in Compiler option contains correct filename, other wise i will not be able to compile anything"
i also just tried to compile the same code above in Dev C and got the error "huh? why in the world are you trying to compile and empty project "
- floodhound2
- ∑lectronic counselor
- Posts: 2117
- Joined: 03 Sep 2006, 16:00
- 17
- Location: 127.0.0.1
- Contact:
take a look here
http://www.cprogramming.com/tutorial/c/lesson1.html
C is easy once you get past the small curve. C++ i cant speak of because i never programmed in it, but i think it is the same just object oriented.
http://www.cprogramming.com/tutorial/c/lesson1.html
C is easy once you get past the small curve. C++ i cant speak of because i never programmed in it, but i think it is the same just object oriented.
Re: C compiling question
There should be no spaces around stdio.h
Main is an int, not a void.
Linux executables have no extension. a.out means assembler output. Assembler output is the end result of a standard invocation of gcc.
Angled brackets mean the C compiler looks for the header file in standard (or supplied with the -I switch) header directories. If you want to use a path, use double quotes.
Better hello world:
Judging from the code, you're reading an old tutorial. Get a newer one.
I'd learn C, not C++.
Emacs doesn't compile any languages (1 exception is elisp, anyway...). You write the code in emacs, then use the standard language tools such as GCC to compile the code. You can use Emacs to code in any language.
Main is an int, not a void.
Linux executables have no extension. a.out means assembler output. Assembler output is the end result of a standard invocation of gcc.
Angled brackets mean the C compiler looks for the header file in standard (or supplied with the -I switch) header directories. If you want to use a path, use double quotes.
Better hello world:
Code: Select all
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
return 0;
}
I'd learn C, not C++.
Emacs doesn't compile any languages (1 exception is elisp, anyway...). You write the code in emacs, then use the standard language tools such as GCC to compile the code. You can use Emacs to code in any language.
I <3 MariaLara more than all of you
- Still_Learning
- Fame ! Where are the chicks?!
- Posts: 1040
- Joined: 11 Jun 2008, 16:00
- 15
- Location: Trigger City