int get_command_line (char * sa) {
char * s;
char * l = fgets(s, 300*5, stdin);
int i = 0;
int j;
int n;
while (i<5){
j = 0;
while (j < 300) {
sa[i][j] = s[n];
if (s[n] == '\"') {
while (s[n]!= '\"' && j < 300) {
sa[i][j] = s[n];
if (s[n] != '\"'){
j+=1;
n+=1;
}
}
} elseif (c == '\n') {
return i;
} elseif (c == ' ') {
i += 1;
break;
} else {
sa[i][j] = c;
j += 1;
while(s[n] != ' ') n += 1;
}
}
}
return 5;
}
The aim is to have the function return the number of arguments made after assigning each of the arguments to a c string stored in an array of five pointers. This is how I declare this:
int main(void)
int n;
char s0[300];
char s1[300];
char s2[300];
char s3[300];
char s4[300];
// There are now 5 strings that can accept user input that is less than 300 chars.
char * sarray[5];
sarray[0] = s0;
sarray[1] = s1;
sarray[2] = s2;
sarray[3] = s3;
sarray[4] = s4;
// These strings are now stored in an array so that multiple inputs may be taken.
n = get_command_line(sarray);
print (sarray, n);
return;
}