LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-11-2009, 06:55 PM   #1
vipin_jss
Member
 
Registered: Aug 2007
Posts: 45

Rep: Reputation: 15
command line argument in c


hii to all

i have a problem related to command line argument in c

#include <stdio.h>

main( int argc, char *argv[] )
{
if( argc == 2 )
printf("The argument supplied is %s\n", argv[1]);
else if( argc > 2 )
printf("Too many arguments supplied.\n");
else
printf("One argument expected.\n");
}



i have this code but i dont know how to execute this code in gcc plz be descriptive thanks
 
Old 05-11-2009, 06:59 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
You don't execute it in gcc, you compile it.

man gcc
holds a host of information to explain how. Have a read, highly
recommendable ;}



Cheers,
Tink
 
Old 05-11-2009, 07:20 PM   #3
bencharluo
LQ Newbie
 
Registered: May 2009
Location: Hangzhou China
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 1
first: gcc -o yourtext yourtext.c
second: ./yourtest parameter1 parameter2...
last: you will get the answer you want
 
Old 05-11-2009, 07:23 PM   #4
vipin_jss
Member
 
Registered: Aug 2007
Posts: 45

Original Poster
Rep: Reputation: 15
i executed this code as
gcc code.c

next for the output i type code 3 it says command not found

when i try ./a.out 34

it is working my problem is why code 3 is not working
 
Old 05-11-2009, 07:25 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
man gcc
/-o



Cheers,
Tink
 
Old 05-11-2009, 07:28 PM   #6
vipin_jss
Member
 
Registered: Aug 2007
Posts: 45

Original Poster
Rep: Reputation: 15
okie thanks i got the point
 
Old 05-11-2009, 07:47 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by vipin_jss View Post
okie thanks i got the point
Good =}

Quote:
Originally Posted by man gcc
Code:
       -o file
           Place output in file file.  This applies regardless to whatever sort of output is being produced, whether it be an executable
           file, an object file, an assembler file or preprocessed C code.

           If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its
           assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing directory name as a command line argument adilwaheed Linux - Newbie 4 03-12-2009 04:01 PM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-15-2008 12:52 AM
Perl command line argument noir911 Programming 8 01-15-2008 05:59 AM
Finding the last command line argument (bash) pete1234 Programming 20 10-30-2006 11:20 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 05:35 PM


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