create name array help beginner
Hi,
I'm tryin got import 5 names into an array, then display the array but as you'll see below it's displaying the array in a strange way.. i believe i am writing the wrong print f code.
Also, i am going on form this to ask the user to enter a name and then compare the entered name to each sring in the asrray using a unction. Any ideas?
code:
Code:
#include <stdio.h>
main()
{
char names[5][5];
char name1[5] = {'D','I','C','K','Y'};
char name2[5] = {'J','O','H','N','Y'};
char name3[5] = {'F','R','E','D','Y'};
char name4[5] = {'P','A','U','L','Y'};
char name5[5] = {'F','R','A','N','Y'};
int x=0;
int y=0;
for( x=0; x < 5 ; x++) {
names[0][x] = name1[x];
} printf("\n");
for( x=0; x < 5 ; x++) {
names[1][x] = name2[x];
}
printf("\n");
for( x=0; x < 5 ; x++) {
names[2][x] = name3[x];
}
printf("\n");
for( x=0; x < 5 ; x++) {
names[3][x] = name4[x];
}
printf("\n");
for( x=0; x < 5 ; x++) {
names[4][x] = name5[x];
}
printf("%s\n", names[0]);
printf("%s\n", names[1]);
printf("%s\n", names[2]);
printf("%s\n", names[3]);
printf("%s\n", names[4]);
}
Print out:
DICKYJOHNYFREDYPAULYFRANY(smilyface)
JOHNYFREDYPAULYFRANY(smilyface)
FREDYPAULYFRANY(smilyface)
PAULYFRANY(smilyface)
FRANY(smilyface)
Thanks in advance