LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2010, 10:48 PM   #1
t1nm@n
Member
 
Registered: Aug 2009
Location: Trivandrum, Kerala, India.
Distribution: Slackware 14.2 x86_64
Posts: 96
Blog Entries: 3

Rep: Reputation: 25
C programming with linux


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....
 
Old 07-10-2010, 10:59 PM   #2
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
Here is a more portable piece of code that will work better on Linux:

Code:
#include <stdio.h>

int main ()
{
    printf("Hello, World!\n")
    return 0;
}
 
Old 07-10-2010, 11:06 PM   #3
t1nm@n
Member
 
Registered: Aug 2009
Location: Trivandrum, Kerala, India.
Distribution: Slackware 14.2 x86_64
Posts: 96

Original Poster
Blog Entries: 3

Rep: Reputation: 25
just a question ken...why choose int mani i dint have any integer values...
 
Old 07-10-2010, 11:16 PM   #4
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
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
 
Old 07-10-2010, 11:22 PM   #5
t1nm@n
Member
 
Registered: Aug 2009
Location: Trivandrum, Kerala, India.
Distribution: Slackware 14.2 x86_64
Posts: 96

Original Poster
Blog Entries: 3

Rep: Reputation: 25
WOW.... thats gr8 so any way i can start learning with c in linux .. i'm new to programming


any books
 
Old 07-10-2010, 11:55 PM   #6
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
Quote:
Originally Posted by t1nm@n View Post
WOW.... thats gr8 so any way i can start learning with c in linux .. i'm new to programming


any books
http://en.wikibooks.org/wiki/C_Programming
 
Old 07-11-2010, 12:16 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
http://www.amazon.com/Beginning-Linu.../dp/1861002971

Note: Please do not use texting shorthand here
 
Old 07-11-2010, 12:42 PM   #8
baxzius
Member
 
Registered: Jan 2010
Location: India
Distribution: ubuntu
Posts: 134
Blog Entries: 1

Rep: Reputation: 21
#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.
 
Old 07-11-2010, 01:01 PM   #9
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Rep: Reputation: 0
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
 
Old 07-11-2010, 03:08 PM   #10
baxzius
Member
 
Registered: Jan 2010
Location: India
Distribution: ubuntu
Posts: 134
Blog Entries: 1

Rep: Reputation: 21
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)

have you configure your kernelheader files?
 
Old 07-11-2010, 04:22 PM   #11
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,200

Rep: Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307
Quote:
Originally Posted by t1nm@n View Post
any books
Buy this. It's the best C tutorial I've found; platform neutral, and easily worth the initial investment.

http://www.amazon.com/Primer-Plus-5t...dp/0672326965/

I read it in 2-3 nights after I got it.

Last edited by dugan; 07-11-2010 at 04:28 PM.
 
1 members found this post helpful.
Old 07-11-2010, 05:58 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-11-2010, 06:36 PM   #13
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 07-11-2010, 07:59 PM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by jlinkels View Post
Every programmer starting to program C should start with Kernigan & Ritchie: The C programming language.
It's easy to find a free PDF copy of it online.

Also, check out Cprogramming.com.
 
Old 07-12-2010, 06:39 AM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by jlinkels View Post
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).

A useful site: http://deitel.com/ResourceCenters/Pr...4/Default.aspx

...

A book on "C" (the C89 version):

http://publications.gbdirect.co.uk/c_book/ -> http://publications.gbdirect.co.uk/c...the_c_book.pdf .

C99 is far better to my taste than C89. On C99: http://www.ibm.com/developerworks/library/l-c99.html .

Last edited by Sergei Steshenko; 07-12-2010 at 06:41 AM.
 
1 members found this post helpful.
  


Reply

Tags
programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration