I need to make a program that takes any amount words from users, then prints those words out with an 's' appended to the end.
The loop should run until the user enters in an empty string (hits ENTER). I know I could do this without making a multidimensional array, but doing it will help me understand my next project.
I'm running into the problem that it only allows 3 inputs from the user before terminating the loop, and I don't understand why.
If I change the #define MaxWord
to 20 or 50, it only allows 1 input from the user before terminating the loop. Can someone help me out?
#include <stdio.h>
#include <string.h>
#define MAX_WORDS 1
#define MAX_LEN 50
int main()
{
char input1[MAX_WORDS][MAX_LEN];
int i = 0;
do
{
printf("Print your word: \n");
gets(input1[i]);
if (strlen(input1[i]) != 0)
{
printf("Here is your word: %ss\n", input1[i]);
i++;
}
} while (strlen(input1[i]) != 0);
printf("Complete");
return 0;
}