Hi, I'm a noob here plz be gentle. My code is supposed to print out all of the command line arguments passed to it. Plus, each argument should be separated from the others with a comma and space. So i just begin to code.
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int i;
for (i=1; i < argc; ++i)
{
cout << argv[i] << "," << " ";
}
}
So i ran it;
RESULT: no-arg-case [1/1]
one-arg-case:
testing,
ERROR: expected testing
RESULT: one-arg-case [0/1]
five-arg:
./runcase: line 39: five-argis: command not found
RESULT: five-arg [1/1]
five-arg-with-comma:
check, if,, this, thing, works,
ERROR: expected check, if, this, thing, works
RESULT: five-arg-with-comma [0/1]
comma=at-end:
a, little, tricky,,
ERROR: expected a, little, tricky,
RESULT: comma-at-end [0/1]
#include <iostream>
int main( int argc, char* argv[] )
{
// print the first n-1 command line args with a comma and a space after each arg
for( int i = 1 ; i < (argc-1) ; ++i ) std::cout << argv[i] << ", " ;
// print the last arg
std::cout << argv[argc-1] << '\n' ;
}
#include <iostream>
int main( int argc, char* argv[] )
{
// print the first n-1 command line args with a comma and a space after each arg
for( int i = 1 ; i < (argc-1) ; ++i ) std::cout << argv[i] << ", " ;
// print the last arg
if( argc > 1 ) std::cout << argv[argc-1] << '\n' ;
}