Code:
#include <stdio.h>
#include <string.h>
int main (int argc, char * argv[]) {
int i, j, k;
if (*argv[1] == '-') {
if (*++argv[1] == 'l') {
j = *++argv[1];
for (i = 2; i< j+2; i++) {
k = strlen(argv[i]);
printf("%s lenght %d \n",argv[i], k);
}
}
else {
printf("try again: \n");
}
}
return 0;
}
when I launch my program for example via commanfd myprogram -l2 Micahel Schumacher the output is:
Michael lenght 7
Schumacher lenght 10
Bus error
I just can't figure what is causing the bus error. My compiler shows that this line if (*argv[1] == '-') is causing the problem.
Any ideas?