ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hey guys i wanted to learn c programming in linux.... but all the tutorials and books are based on windows
_____________________________________________________
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("hello");
getch();
}
______________________________________________________
that was the first program i did with bcc32 compiler in windows.... what shuld i do for the same in linux....
why choose int mani i dint have any integer values...
It's the standard for writing C prorgrams on UNIX-like OSes (this includes Linux). The return statement at the end of main() spits out a zero to the shell, so that it can be used as, for example, an error code if something goes wrong in the program (invalid input, etc.):
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
if(strcmp(argv[1],"something"))
printf("You entered the right argument! :D\n");
else //If the user gives anything other than the word "something" as an argument
{
printf("Error, you entered %s instead!",argv[1]);
return 1; //Return an error code. This can be anything,
//as long as it's not 0, as that's the
//standard code for "success".
}
return 0; //If everything went smoothly, go ahead and return nothing.
}
If I were to call this program "something", and I ran ./something "something" in the shell, it would return a 0 to the shell, which could be used in for example a shell script to show that the program ran successfully. Had I just ran ./something "nothing" (or anything other than "something", or just no argument at all), then it would have returned a one to the shell, and I could use that in a shell script to show that the program failed.
Gurus, if I missed a few important details, please don't hesitate to provide them. I'm a little tired/sleepy as I write this, so I'm probably not able to concentrate as well as I could.
Last edited by MrCode; 07-10-2010 at 11:32 PM.
Reason: fixed the parentheses around the if statement :-P
#include<stdio.h>
/*#include<conio.h> this is not used in linux c programming. because conio.h doesnt exist in linux.*/
void main()
{
clrscr();
printf("hello");
//getch(); you cannot use this function because conio.h doesnt exist in linux
} SO what i am coming to say is that you may programmed in turbo c or c++.But Friend a slight different in linux programming.you have understand about following sections for studying linux C programming.
1.Compilation
2.linking.
3.making.
4.Running or Execution.
And understand.... like windows C programming,there is no rules to use specific IDE. you can edit your c programs on any editor. but i heard code::blocks are the greatest C programming IDE in linux. it helps the programmers very well.
Well if you are so so so so so lazy to study the new functions and headerfiles of linux c programming. i will tell you a adventorous trick ways.
enter into the location
/usr/include
you may see many files concern extension header file. just view the headerfile and read the prototypes of functions. just put it onthe program with apropriate specification of header files.
start your programming
PLEASE UNDERSTAND LINUX DOESNT CONTAINS graphics.h HEADERFILE. BECAUSE INSTEAD OF IT. YOU HAVE TO SDL LIBRARY FUNCTIONS.
Hi
Int main comes because when you will run a program it should return a status to operating status(Linux),so when you program will become a process it will return a status of it to Linux,whether program worked correctly or not.
second thing for Learning C/C++....you can use Anjuta IDE
People i would like to say that..
Do you think that could your linux box can compile source codes of softwares with perfectly.
if you dont have enough library dependencies then surely you cannot play with open source or hacking
Dont you understand?
hey people please update your libraries.
do you wanna write Graphical user interface programs(gtk libraries)
do you wanna write Ncurses programs (ncurses libraries)
do you write graphics related programs(games) (SDL libraries)
do you wanna write kde based windows(qt libraries)
Every programmer starting to program C should start with Kernigan & Ritchie: The C programming language.
Examples in the book work in Linux, when the book was written the authors worked on Unix.
There is no shortcut in learning programming, you have to put in effort to get programs out.
jlinkels
Even though I myself started with the book about 30 years ago, I'm not sure it's the case today.
Generally speaking, regardless of of programming language, it's worth studying two things in parallel - the language by a textbook and the same language by its standard. For the latter: http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf (for C99).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.