|
How do you program with C on Linux?
|
| Author |
Message |
marioluvsfries
Unregistered
|
How do you program with C on Linux?
I tried using Emacs to program in C, but that work out so well and I've tried csh (C Shell) in my terminal but I don't know how to invoke a C program...
This is the source for the simple program example from the C 2ND Edition programming Guide from Que books:
/*this C program prints a message on the screen */
#include <stdio.h>
main()
{
printf("This is my first program \n");
}
So does anyone know how to get C coding to work in a terminal? This is ridiculous! Linux is almost completely written in the language and I can't even practice it! Arghh!
|
|
| 09-08-2012 05:58 PM |
|
 |
chridd
Posts: 88
Group: Registered
Joined: Sep 2012
Status:
Offline
|
RE: How do you program with C on Linux?
You need to compile the program first, and thus need a compiler. gcc is a common compiler for Linux, and may or may not be pre-installed; to use it, type:
replacing hello.c with the name of the file containing your code. (If you have a different compiler, you can use that instead.)
This will create, by default, a file called a.out which you can run by typing
Not sure if I'm an Aspie, but I seem to at least be similar in some ways. Aspie score: 111 out of 200.
|
|
| 09-08-2012 08:16 PM |
|
 |
marioluvsfries
Unregistered
|
RE: How do you program with C on Linux?
Thank you chridd it worked
|
|
| 09-08-2012 08:20 PM |
|
 |
Gareth
Administrator
      
Posts: 11,497
Group: Administrators
Joined: Jul 2004
Status:
Offline
|
RE: How do you program with C on Linux?
I'm quite surprised the book you're following hasn't gone over compilation actually - i'd suggest you find a different guide.


“Lanie, I’m going to print more printers. Lots more printers. One for everyone. That’s worth going to jail for. That’s worth anything.” - Printcrime by Cory Doctrow
|
|
| 09-09-2012 08:33 AM |
|
 |
marioluvsfries
Unregistered
|
RE: How do you program with C on Linux?
Why won't GCC work with C++ ? Or do I have to find a C++ compiler ? .... :/
|
|
| 09-19-2012 12:17 AM |
|
 |
marioluvsfries
Unregistered
|
RE: How do you program with C on Linux?
This is the C++ code:
#include <iostream.h>
void f(int intparm)
{
cout << intparm << end1;
}
int main()
{
long int j =2147483647;
f(j+1);
f(123);
f('A');
f(9.99);
return 0'
}
Which was copied out of the book but I keep getting this error message:
predict.cpp:1:23: error: iostream.h: No such file or directory
predict.cpp:15:11: warning: missing terminating ' character
predict.cpp:15: error: missing terminating ' character
predict.cpp: In function ‘void f(int)’:
predict.cpp:5: error: ‘cout’ was not declared in this scope
predict.cpp:5: error: ‘end1’ was not declared in this scope
predict.cpp: In function ‘int main()’:
predict.cpp:16: error: expected ‘;’ before ‘}’ token
|
|
| 09-19-2012 12:41 AM |
|
 |
Gareth
Administrator
      
Posts: 11,497
Group: Administrators
Joined: Jul 2004
Status:
Offline
|
RE: How do you program with C on Linux?
Why won't GCC work with C++ ? Or do I have to find a C++ compiler ? .... :/
g++ is what you want


“Lanie, I’m going to print more printers. Lots more printers. One for everyone. That’s worth going to jail for. That’s worth anything.” - Printcrime by Cory Doctrow
|
|
| 09-19-2012 02:45 AM |
|
 |