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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

really simple one. 2

Status
Not open for further replies.

fortytwo

Technical User
Apr 18, 2000
206
GB
Hi,

I have the following program:
[tt]
#include <stdio.h>
int main(0)
{
printf&quot;Hello World\n&quot;;
return(0);
}[/tt]

and it seems to compile (the binary appears) and there are no errors given, but when I try and run it I get

[tt]bash: command not found[/tt]

in linux (redhat6.2)

anyone got any ideas? [sig]<p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br> [/sig]
 
I am not really familiar with bash, but this problem sounds like missing path entry.
Try to execute the binary in following way
./name of Binary.

Make sure that the binary has execute permission. [sig]<p>hnd<br><a href=mailto:hasso55@yahoo.com>hasso55@yahoo.com</a><br><a href= > </a><br> [/sig]
 
Hi,

This *really* compiled? Here's what I got from gcc on Redhat 6.2:

% gcc t.c
t.c:3: parse error before '0'
t.c: In function 'main'
t.c:5: parse error before string constant

Try this below:

#include <stdio.h>
/* void not '0' */
int main(void)
{
/* don't forget the parens */
printf(&quot;Hello World\n&quot;);
/* return is not a function, no parens needed */
return 0;
}

Regards,
[sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
Sorry, missed that. It is like this:
[tt]
#include <stdio.h>
int main(0)
{
printf(&quot;Hello World\n&quot;);
return(0);
}[/tt]

directly out of the oreilly book, and I am compiling it like this:

[tt]cc -g -ohello hello.c[/tt]

and also:

[tt]gcc -g -Wall -ohello hello.c[/tt]

I guess it could be due to trying to run it using an invalid path so ./hello might work, but I would have thought just typing hello would work. I will check the execute permissions tonight (my machine is at home). Thanks for all the help :) [sig]<p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br> [/sig]
 
Unless you are compiling it in one of your system path directories (such as /bin/) then you cannot execute it without specifying the path, even if you are in the same directory as the file. It would work on a Windows machine without using the path if you are in the same directory, but not on a *nix machine.

Regards,
Gerald
[sig][/sig]
 
I don't see how that's compiling. My understanding is that you either have to declare main as int main(void) or int main(int argc,char **argv). I tried compiling your code with the options you gave, but still get a parse error (because of the '0' parameter in main()).

To execute a program without specifying its absolute path, the shell needs to know where to find it (i.e. the program needs to be somewhere in your PATH). You can place '.' in your path but that's generally a bad idea. If you DO do this, make sure it's at least the last directory in your path.

Regards, [sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
B*gger, I got it wrong again :)

[tt]#include <stdio.h>
int main()
{
printf(&quot;Hello World\n&quot;);
return(0);
}[/tt]

That is the one. I thing the problem is probably that I am not apecifying the path correctly. I am off home to test it.

[sig]<p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br> [/sig]
 
thanks everyone, it works with:

./hello

Thanks [sig]<p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top