Program for storing multiple letters
Code:
#include<stdio.h>
int main (void)
{
unsigned int i;
char array[6]={'s','e','a','r','c','h'};
for(i=0; i<6; i++)
{
printf("print letter : %c \n", array[i]);
}
return 0;
}
print letter : s
print letter : e
print letter : a
print letter : r
print letter : c
print letter : h
Program for storing multiple strings
Code:
#include<stdio.h>
int main (void)
{
unsigned int i;
char array[6]={"stuck","enk","andy","ratch","cemp","harry"};
for(i=0; i< 6; i++)
{
printf("print letter : %s \n", array[i]);
}
return 0;
}
hello.c:6:26: error: excess elements in char array initializer
char array[6]={"stuck","enk","andy","ratch","cemp","harry"};
^~~~~
I think my array size is not enough to store these six strings in array
What's the reason of error and how can I fix it.