LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-25-2011, 07:25 AM   #1
Vaibhav Ahlawat
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
C Programming


I have been doing c and c++ programming in windows with turbo c/c++ compiler , but now i have switched to ubuntu 11.04.
Could somebody help me doing c++ programming with linux terminal.
Thanx in advance.
 
Old 08-25-2011, 07:44 AM   #2
vijayavel
LQ Newbie
 
Registered: Aug 2011
Posts: 9

Rep: Reputation: Disabled
c programming

Hey its very simple ya.
go to open vi editer or gediter in your terminal.

Then type c program in it and save with extension of .c
example: test.c

Then using gcc to compile it.
compile: gcc filename.c -o filename
run: ./filename

example:
compile: gcc test.c -o test
run: ./test

thats it.
 
Old 08-25-2011, 09:02 AM   #3
ac_kumar
Member
 
Registered: Aug 2011
Distribution: Ubuntu, Fedora
Posts: 175

Rep: Reputation: 9
u need to first install gcc to run c or c++ programme:-
to install gcc run this command:
$sudo apt-get install gcc

once gcc is installed check if it's working by running this command :
$gcc
if it shows no input file gcc is working.
than u can make a sample c programme:
$gedit test.c
enter this in test.c
#include<stdio.h>
void main()
{
printf("\nHello World!\n");
}
than save file and return to terminal
run to this command to compile c programme:
$gcc test.c
to make a output file run this command
$gcc test.c -o test
to execute compile programme run this:
./test
 
Old 08-26-2011, 12:20 AM   #4
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
to compile c++ in linux you will have to install g++ only gcc will not be enough.
Code:
sudo apt-get install g++
then to compile the program

Code:
g++ filename.cpp
Execute the program using

Code:
./a.out
 
Old 08-26-2011, 02:26 AM   #5
salemeni
Member
 
Registered: Aug 2011
Posts: 64

Rep: Reputation: Disabled
You can also use kdevelop (An IDE)
http://kdevelop.org/
 
Old 08-26-2011, 02:29 AM   #6
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
Hi, welcome to LQ!

Foremost you have to make sure you distinguish between C/C++ and
Borland features. We get so many inquiries here regarding such
and such feature not working in Linux, it's not even funny :}


Cheers,
Tink
 
  


Reply



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 > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:51 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