Exemple #1
0
int main( int argc, char *argv[] )
{
  char *stringBuffer;

  //  Check number of user supplied arguments.
  if( argc < 2 )
    {
      fprintf(stderr, "usage: you have to enter 1 argument.\n" );
      exit( -1 );
    }

  if( argc != 2 )
    {
      fprintf( stderr, "usage: %s string.  This reverses the string "
	       "given on the command line\n", argv[1] );
      exit( -1 );
    }
  
  // Copy the argument so we can make changes to it
  //stringBuffer = (char*) malloc( strlen(argv[1]) );
  //strcpy( argv[1], *stringBuffer );
  stringBuffer = argv[1];

  // Reverse the string
  reverseIt( stringBuffer );

  // Print the reversed string
  printf( "the reversed string is '%s'\n", stringBuffer );

  return 0;
}
Exemple #2
0
int main( int argc, char *argv[] )
{
    char *stringBuffer;
    
    //  Check number of user supplied arguments. 
    char sterr[]="string";
 
    if( argc != 2 )
    {
      // change following fprintf to printf and varable to end of printf
      printf( "usage: %s string.  This reverses the string given on the command line\n", sterr );      

      exit( -1 );
    }

    // Copy the argument so we can make changes to it
    stringBuffer = (char*)malloc( strlen(argv[1]) +1 );   // array was cutting
    //off NULL character at the end: \0, so I added one character for the NULL
    //character
    strcpy( stringBuffer, argv[1] );

    // Reverse the string
    reverseIt( stringBuffer );

    // Print the reversed string
    printf( "the reversed string is '%s'\n", stringBuffer );

    return 0;
}