Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a C program in Linux

Status
Not open for further replies.

pwel

Programmer
Aug 18, 1999
79
GB
I am a newbie to the world of Linux, and i am trying to execute a C program that i wrote.<br>
<br>
I created a file called ctest.c, just a simple program: -<br>
<br>
#include &lt;stdio.h&gt;<br>
int main()<br>
{<br>
int index;<br>
for(index=0; index&lt;10; index++)<br>
{<br>
printf("A test program in Red Hat Linux 6.0\n");<br>
}<br>
return 0;<br>
}<br>
<br>
I compiled the program as follows: -<br>
<br>
gcc -o myprog ctest.c<br>
<br>
The program compiled successfully, but when i come to execute the prog with the following command: -<br>
<br>
. myprog<br>
<br>
I get the following error messagfe: -<br>
<br>
.:myprog: cannot execute binary file<br>
<br>
Can anyone tell me what i'm doing wrong?<br>
<br>
Any help would be much appreciated.<br>
<br>
Paul Welding.
 
Did you remember to make it executable?<br>
chmod +x myprog<br>
will make it executable, but if you want other users to be able to use it also, maybe<br>
chmod a+x myprog.<br>

 
if make a directory like /usr/src/test then put this directory in your path then when you compile a program you won't have to put ./ before every executeable. <br>
<br>
also put in #include (stdlib.h)<br>
<br>
if when you start programming loads and you don't see a message on screen ie:<br>
<br>
printf("blarr blarr");<br>
<br>
try flushing the buffer the one for output is <br>
<br>
fflush(stdout);<br>
<br>
for input<br>
<br>
fflush(stdin);<br>
you should flush the input buffer every read of the keyboard.
 
Thanks for your help Octalman & sijones, your solutions solved the problem.<br>
<br>
Thanks again.<br>
<br>
Paul Welding.
 
hi
Nothing to worry about it. unix has inbuilt feature for writing and executing c annd C++ programs. linux can compile many other programs also for maximum all softwares.
u can compile c program execute the command in the directory in which the c file is present. the file extension must be .c
$ cc <filename.c>
and for compiling the c++ programs
$ CC <filename.cpp>
case sensitive.

bye
SANTOSH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top