Thursday, July 30, 2009

A 'C' Program in Linux Does not yield any answer. Why?

This question is related to Linux. I have Red Hat Linux 8.0 installed. The shell programming works fine but when I try to execute a 'C' Program No result is displayed. However the errors, if any, are displayed. The Test Program is


"#include %26lt;stido.h%26gt;


main()


{


printf("Hello");


}


This simple program compiles properly without errors but does not display Hello. I tried to execute by typing ./%26lt;program name%26gt; but to no avail.





I also tried to set my profile by adding TERM=vt100 and export $TERM. thinking the the terminal might not be properly configured. but this also has not helped me. Can any one suggest me an solution to this weird problem? The same program works at my College Computer. Any settings I have missed?

A 'C' Program in Linux Does not yield any answer. Why?
the syntax looks OK. However there is a quotation mark before your #include. The compiler would probably give you an error if it is in your actual source code.





Have you verified that you are actually producing an executable file? Compilation is actually a two stage process. First the compiler creates an object file and then the object file(s) are linked together to form the actual executable.





Unless you specify otherwise the default executable name for most compilers/linkers is "a.out". Try typing "./a.out" and see if that does it for you.
Reply:Try:





printf("Hello\n");





The \n is the newline character, sometimes console apps are finicky about actually flushing the output until a newline is encountered. You can also do:





printf("Hello");


fflush();





To force the output to print to the screen.
Reply:the CORRECT program is %26gt;





#include %26lt;stdio.h%26gt;


int main()


{


printf("Hello World/n");


return (0);


}





it's either you need to return a value from the function OR you need a return type.. in this case INT





if it works on another computer? is it a pc etc, different compiler? as some forgive such things..





if THAT doesn't work something odd is going on with ur pc








c'mon guys/gals this is basic c. probably everyones first program.
Reply:check your a.out file
Reply:I think there is some problem with ur installation because u said u have da same probs in da college. Anyway check da same with ANJUTHA. It may help u. Try to trace the location of ur code in ur system. Move to that directoty and then try "./a.out". the ./a.out says to wxecute the one compiled latest. If u still face problems try to upgrade to RH9 or Core 4. If u need Core 4 plz contact me.


No comments:

Post a Comment