In addition to what the others have said, you should turn up the warning on your compiler. Since you use the idiom
int n;
scanf("%d", &n);
char str[n];
I assume you are using linux or mingw, since MSVC does not accept "variable length arrays", in which case you should add (at least)
-Wall -Wextra
to the compile command. If you had done that, you would have got a warning about this:
char t[n];
char str[100];
/ * ... assignment of str ommited ... */
for(i = 0; i < n; ++i)
{
t[i] = str;
}
Some other observations:
scanf("%d\n", &n)
doesn't do what you think. Try this and see what happens:
int n;
char str[100];
printf("How may strings? ");
scanf("%d\n", &n);
int i;
for(i = 0; i < n; ++i) {
printf("Enter string %d : ", i);
fgets(str, sizeof str, stdin);
}
What happens if the user enters more than 100 chars?
What happens if the user enters the string "ABCDEFGHIJKLMNOP"?
What happens if the user enters the string "abcd efgh"?