String array in C
#include <stdio.h>
int main(void){
char str[4][20]={"Alex","Roan","Allen","Roman"};
int i;
for(i=0;i<=3;i++){
printf("%s \n",str[i]);
}
return 0;
}
Output is here
Alex
Roan
Allen
Roman
Reading names and storing in string arrays to display
You can read full name ( with space ) and then display the same.
#include <stdio.h>
#include <string.h>
int main(void){
char str[4][20];
int i;
for(i=0;i<=3;i++){
printf("Enter one name \n");
gets(str[i]);
}
for(i=0;i<=3;i++){
printf("%s\n",str[i]);
}
return 0;
}
« Basics of array
This article is written by plus2net.com team.
plus2net.com