Hi all,
after alot of java i've decided to start learning some C, i've an exercise that i cannot complete because i've a strange (to me) behaviour, here's the code
and here is the terminal outputCode:#include <stdio.h>
#include <stdlib.h>
int main()
{
char *strings [10];
int i, n = 4, str_size = 255;
printf ("Enter %d strings to sort:\n", n);
for (i=0; i<n; i++) {
strings[i] = (char *) malloc (str_size);
scanf ("%s", &strings[i]);
}
printf("\nRESULT:\n", &strings[i]);
for (i=0; i<n; i++) {
printf("%s \n", &strings[i]);
}
}
What happen to the "three" number? in general all string with a length greater then 3 are concatenated with the following string ...Code:Enter 4 strings to sort:
one two three four
RESULT:
one
two
threfour
four
i've re-read the scanf documentation but really can't find where's the mistake