Trying to add a slash to the end of a string that is pulled from an argument (linux). I read in the argument just fine, then add the slash and poof - no more variable. I trimmed it down to bare bones and it's still doing it. Here's the code:
Code:
#include <stdio.h>
#include <string.h>
int main( int argc, char *argv[] ) {
int i;
char * first_arg = argv[1];
char * second_arg = argv[2];
char * third_arg = argv[3];
char fullcommandline[255] = "";
for( i = 0 ; i < argc ; i++ ) {
strcat(fullcommandline, argv[i]);
strcat(fullcommandline, " ");
}
i = strlen(second_arg);
printf("last character in second_arg is: %c\n",second_arg[i-1]);
if (second_arg[i-1] != '/') {
strcat(second_arg, "/"); // Also have tried "/\0" here w/ same results
}
i = strlen(second_arg);
printf("last character in second_arg is now: %c\n",second_arg[i-1]);
printf("After change:\n");
printf("\tCommand Line : %s\n",fullcommandline);
printf("\tfirst_arg : %s\n", first_arg);
printf("\tsecond_arg : %s\n", second_arg);
printf("\tthird_arg : %s\n\n", third_arg);
return 0;
}
Here's the output:
Code:
user@localhost: ~$ ./test -something ./a_directory ./anotherdir
last character in second_arg is: y
last character in second_arg is now: /
After change:
Command Line : ./test -something ./a_directory ./anotherdir
first_arg : -something
second_arg : ./a_directory/
third_arg :
thoughts?
Thanks