| | |
passing command line arguments
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
I'm trying to pass arguments to my program so that I can store them into an array. For some reason my IDE/compiler is treating the blank space in between arguments as an argument. I'm using bloodshed, but it doesn't say anything about a seperation character. Can anyone tell me what I'm doing wrong?
I'm doing something like this:
Bob Bill
that should be two parameters, but for some reason it returns three.
I'm doing something like this:
Bob Bill
that should be two parameters, but for some reason it returns three.
It appears to work for me. The version of my Dev-C++ IDE is 4.9.9.2. One should note that the first parameter is always the name of your program.
This is the program I used for testing.
This picture shows how I passed the parameters.

And this is my output.
This is the program I used for testing.
C Syntax (Toggle Plain Text)
#include <stdio.h> int main(int argc, char *argv[]) { if ( argc >= 3 ) { printf( "arg[1] = %s\n", argv[1] ); printf( "arg[2] = %s", argv[2] ); } getchar(); return 0; }
This picture shows how I passed the parameters.

And this is my output.
C Syntax (Toggle Plain Text)
arg[1] = Bob arg[2] = Bill
•
•
•
•
Originally Posted by server_crash
I'm trying to pass arguments to my program so that I can store them into an array. For some reason my IDE/compiler is treating the blank space in between arguments as an argument.
C Syntax (Toggle Plain Text)
c:> myprogram "This is one parameter" <Enter>
in the above, argc will be 2, argv[0] == the name of the program and argv[1] == "This is one parameter". Without the quotes, argc == 5 and there will be 6 strings in argv.
![]() |
Similar Threads
- Command Line Arguments (C#)
- command line arguments help (C)
- To fetch data through command line arguments (C++)
- HELP!!!need help with command line arguments and creating a package in java. HELP!!!! (Java)
- command line arguments (C++)
- Command-line Arguments. (C++)
Other Threads in the C Forum
- Previous Thread: Counting occurences in C
- Next Thread: Today Question
Views: 7134 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable feet fflush fgets file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide infiniteloop initialization interest intmain() kilometer lazy license linked linkedlist linux linuxsegmentationfault list match matrix meter microsoft multi mysql oddnumber odf open openwebfoundation pattern pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scheduling segmentationfault send shape single socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user voidmain() win32 win32api windows.h






