LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 11-20-2013, 02:53 AM   #1
goldengriff
LQ Newbie
 
Registered: Nov 2013
Posts: 14

Rep: Reputation: Disabled
Question execute a programm


hi dear's,
how and where i can execute below code??

int main()
{
system("ls");
return 0;
}

thanks
 
Old 11-20-2013, 03:16 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
This is a little C program that does a system call to execute the ls command (pretty not useful, since you can do ls directly from the shell). Anyway, you have to write the code in a text file and then compile it using gcc. Run the resulting executable (a.out by default) and you will get a list of the files in the current working directory.
 
1 members found this post helpful.
Old 11-20-2013, 03:40 AM   #3
goldengriff
LQ Newbie
 
Registered: Nov 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
i run nano main.c and write below code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("\nHello World,\nWelcome to my first C program in Ubuntu Linux\n\n");
return(0);
}
when i run above programm,system show below error ,why??
root@goldengriff:/home/goldengriff/CCPP/HelloWorld# ./main.c.save
./main.c.save: line 1: syntax error near unexpected token `newline'
./main.c.save: line 1: `#include<stdio.h> '
 
Old 11-20-2013, 04:08 AM   #4
tigerton
LQ Newbie
 
Registered: Nov 2013
Posts: 24

Rep: Reputation: Disabled
Before running, you have to compile it!!!!!!
Type:

Code:
gcc main.c -o main
Then you can run it:

Code:
./main
 
1 members found this post helpful.
Old 11-20-2013, 05:04 AM   #5
goldengriff
LQ Newbie
 
Registered: Nov 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
when i compile code,below error showed:
test.c:1:21: fatal error: iostream.h: No such file or directory
compilation terminated.

Last edited by goldengriff; 11-20-2013 at 05:07 AM.
 
Old 11-20-2013, 05:24 AM   #6
tigerton
LQ Newbie
 
Registered: Nov 2013
Posts: 24

Rep: Reputation: Disabled
Post the code
 
Old 11-20-2013, 05:32 AM   #7
goldengriff
LQ Newbie
 
Registered: Nov 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
#include<iostream>
main()
{

cout<<"hello";
return(0);
}

Last edited by goldengriff; 11-20-2013 at 05:41 AM.
 
Old 11-20-2013, 05:43 AM   #8
tigerton
LQ Newbie
 
Registered: Nov 2013
Posts: 24

Rep: Reputation: Disabled
Here's the right code:

Code:
#include<iostream>
#include <stdio.h>

using namespace std;

main()
{

cout<<"hello";


}
for compiling it:

Code:
g++ test.cpp -o test
for running it:

Code:
./test
Keep studying!!!!!!!
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How window in programm can be resized by another programm. rexStart Programming 1 09-23-2008 02:47 AM
Programm TV online dyool Linux - Software 2 09-03-2006 03:39 AM
compile a programm hraposo Fedora 5 07-28-2006 01:11 PM
first opengl programm sakr Linux - Newbie 3 12-28-2005 11:35 AM
Programm like DriveImage? morto Linux - Software 2 02-01-2005 09:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 02:49 PM.

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