Entering data into array of char pointers
Hi,
I'm trying to enter the days of the week into this array of char pointers, but the output is strange.
Code:
Please enter the days of the week:
Day 1: Monday
Day 2: tuesday
Day 3: Wednsday
Day 4: Thurday
Day 5: Friday
Day 6: Saturday
Day 7: Sunday
The days of the week are:
MondtuesWednThurFridSatuSunday
tuesWednThurFridSatuSunday
WednThurFridSatuSunday
ThurFridSatuSunday
FridSatuSunday
SatuSunday
Sunday
Is this somehow a problem with the \0 not getting added to each element?
Code:
#include <stdio.h>
main()
{
char * days[7];
int day;
printf("\nPlease enter the days of the week: \n\n");
for(day=0; day<7; ++day)
{
printf("\nDay %d: " , day+1);
scanf("\n%s" , &days[day]);
}
printf("\nThe days of the week are: \n\n");
for(day=0; day<7; ++day)
{
printf("\n%s" , &days[day]);
}
}
Any help would be appreciated.