Here's the source of your problem:
for (int i = 0; i < 200; i++)
{
a[i]="hello ";
The compiler doesn't know your intent here, so every element of a[]
is assigned a pointer to the same string
a[0] == a[1] == a[2] == a[3] == a[4] == ... a[199]
Even if this worked, the problem is that all elements of a now point to a char array of size 7 {'h', 'e', 'l', 'l', 'o', 0}
. You can't stract
onto the end of them.
You need to ensure that each element of a[]
has a pointer to a unique storage space and that it is large enough to receive your strings. If your a[]
elements are already pointing somewhere valid, what you need to do is:
for (int i = 0; i < 200; i++)
{
strcpy(a[i], "hello ");
}