I'm writing a code that's supposed to find the spaces in the string and separate the parts before and after them in different string arrays. The first problem would be that the scanf doesn't even read my string properly, but also I haven't worked with strings in C before and am curious if it's correct (especially with the a[] array).
char expr[50];
char *a[50];
scanf("%s",expr);
int i=0;
int j=0;
while (strlen(expr)!=0){
if (expr[i]==' '){
strncpy(a[j],expr,i);
strcpy(expr,expr+i+1);
j++;
i=0;
}
else {
if (strlen(expr)==1){
strcpy(a[j],expr);
strcpy(expr,"");
j++;
i=0;
}
else i++;
}
}
i=0;
for (i=0; i<j; i++){
printf("%s\n",a[i]);
}
return 0;