Peter_APIIT Posted January 27, 2007 Report Share Posted January 27, 2007 Few days ago, i have installed Mandriva Linux 2007 on computer. I am a newbie to computer and programming also. Is there any methods to check the software isntalled at my computer ? Besides that, i also have another problem which is GCC compiler problem. When i typed gcc /home/nicholas_tse/C/Welcome.c -o Welcome.c , the konsole return an error message which is no newline at end of the file. I don"t know what happen to my program but i can sure that my program is very simple. Program as below: #include<stdio.h> main() { printf("Welcome to the Linux World"); } Your help will greatly appreciated by me any others who have same problem. Thank for your help. [moved from Everything Linux by spinynorman] Quote Link to comment Share on other sites More sharing options...
dexter11 Posted January 27, 2007 Report Share Posted January 27, 2007 If it needs a newline then give it the new line. Place the cursor after the closing }, which is the end of the file now, and press Enter. Save the file and compile it. Quote Link to comment Share on other sites More sharing options...
Peter_APIIT Posted January 27, 2007 Author Report Share Posted January 27, 2007 I have try your solution but seems the terminal show much more error than before. After modification, my code is as below: #include<stdio.h> main() { printf("Welcome to the Linux World"); } My Error message as below: Welcome.c:10:850: Warning: null character ignored There are many much more error messages that i not showing here but it is almost similiar with the one i post here. The others error messages is no newline at the ned of file. I run out of idea how to fix it. I bag you please help me. I in trouble. Your help is greatly appreciated by me. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
ffi Posted January 27, 2007 Report Share Posted January 27, 2007 (edited) I tried to compile and it worked after the newline character, I did however need to change the output file name Edited January 27, 2007 by ffi Quote Link to comment Share on other sites More sharing options...
dexter11 Posted January 27, 2007 Report Share Posted January 27, 2007 Well yeah this: gcc /home/nicholas_tse/C/Welcome.c -o Welcome.c won't work because the output filename is the same as the source file. Quote Link to comment Share on other sites More sharing options...
Peter_APIIT Posted January 29, 2007 Author Report Share Posted January 29, 2007 Could you please guide me the correct syntax how to show the gcc features at console ? Please forgive my stupidness. Your help is greatly appreciated by anoyone who don"t know. Thanks Quote Link to comment Share on other sites More sharing options...
dexter11 Posted January 29, 2007 Report Share Posted January 29, 2007 You should compile c programs with the following syntax gcc source_file It will compile source_file and create a binary file called a.out. If you want the output file to have a different name you use the -o switch just like you did. gcc source_file -o output_file Source_file and output_file must have a different name. In your command line they have the same name: gcc /home/nicholas_tse/C/Welcome.c -o Welcome.c Change the output file name from Welcome.c to something else. Like plain Welcome.One more thing #include<stdio.h> Leave a space after include #include <stdio.h> Quote Link to comment Share on other sites More sharing options...
tyme Posted January 29, 2007 Report Share Posted January 29, 2007 You usually name output files with the .out extension: gcc /home/nicholas_tse/C/Welcome.c -o Welcome.out While this isn't necessary, it's pretty standard and makes identifying the file easier. two other pointers: Always return something from a function, even if it's zero. If a function isn't going to be passed any variables, declare it void. With these two pointers in mind, we get: #include <stdio.h> main(void) { printf("Welcome to the Linux World"); return 0; } differences are marked in red. Quote Link to comment Share on other sites More sharing options...
dexter11 Posted January 29, 2007 Report Share Posted January 29, 2007 One more thing the main function must return int. I don't know about gcc but some compilers give a warning about it. So it should be int main(void) Quote Link to comment Share on other sites More sharing options...
Peter_APIIT Posted January 30, 2007 Author Report Share Posted January 30, 2007 Hey guys, i try to modify the program with the help of you all but the problem still exists. The console shows some warning on it which is Warning : No newline at the end of file I don"t know what wrong with it. Thanks for your help. Hope GOD will blessed you. Quote Link to comment Share on other sites More sharing options...
dexter11 Posted January 30, 2007 Report Share Posted January 30, 2007 I tried to compile this file now and I got the same error message like you. I did what I wrote in my first post in this topic and it helped. Quote Link to comment Share on other sites More sharing options...
hippocampe Posted January 30, 2007 Report Share Posted January 30, 2007 The message regarding newline is a warning. You can ignore it because the compiler will usually continue and produce an executable. However errors will prevent a program from compiling. Error messages are usually in red if you have gcc-color installed. Quote Link to comment Share on other sites More sharing options...
tyme Posted January 30, 2007 Report Share Posted January 30, 2007 The reason for the new line is because it's part of the ANSI standards. By putting an extra line at the end, you're making your program ANSI standards compliant. This is a good thing ;) Check to see if the program was actually compiled. By default, warnings will be printed out but the program will still compile. If this is not occurring, then we need to look for the setting which causes gcc to run with warnings as errors. Note that, by default, you will not receive any messages that it was successfully compiled from gcc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.