Originally Posted by
laurenlb
Im just starting to learn about strings. Right now I'm just trying to prompt the user to input multiple words and then use the scanf function. Since I am just learning strings there may be other errors. Feel free to address those as well. Thanks.
I can not figure out what to put after the %s in this situation. Or is a for loop not the right way to go about this problem?
Code:
int
main()
{
char *string1;
int i;
for (i=0; i<9; i=i+1)
{
printf("Please enter a word:\n");
scanf(%s, );
}
}
Well, amongst the many possibilities you could do this...
Code:
int main (void)
{ int i;
char words[10][25] = {0};
// gather input
for (i = 0; I < 20; i++)
{ printf("Enter word #%d : ", i);
scanf(" %24s", words[i]); }
// display the results
printf("\n\n");
for (i = 0; i < 10; i++)
printf("Word #%d is : %s\n",i, words[i]);
return 0; }
Go ahead try it out... it should work... but then go look up each function and study them until you understand what they do and how they contribute to the overall solution.