LinuxQuestions.org
Visit Jeremy's Blog.
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, 08: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, 08: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, 10: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, 01: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, 03: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, 03:29 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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


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




All times are GMT -5. The time now is 03: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration