Hey!
I'm writing a program and currently having trouble with getting a written line typed in by the user to be copied correctly into another array...
I'm using a for-loop to run through the original char-array, but if I type in "Hello" the program will give me this result:
Param chararray: hello
ello
llo
lo
o
(which is exactly the same as the "midl"-array, but not at all what it want >;o) Hehe...)
What is causing this, and how do I avoid it?
int main(int argc, char *argv[])
{
int teller = 1;
while(teller!=0){
printf("ifish %d > ", teller);
teller++;
char *returnkode;
returnkode = fgets(text, maxl, stdin);
printf("DEBUG --> Du skrev: %s \n", text);
int i;
int j=0;
int parateller=0;
for(i=0; i < (strlen(text)); i++){
printf("Midl: %s\n", midl);
strcat((char *)&midl, &text[i]);
if((j=(isspace(text[i]))) != 0){
printf("blank!\n");
param[parateller] = malloc(sizeof(midl));
strcpy(param[parateller], midl);
printf("Parateller: %d\n", parateller);
parateller++;
}
}
printf("Param chararray: %s\n", param[0]);
}
}