Hello, I am still green to the C programming language. I am writing a multi-dimensional array program to store strings into an array. The program requires error checking to avoid overflow.
I am using Visual Studio 2008.
I am using a Windows O/S.
The program runs fine on the first past through, but skips over the prompt on the next run.
Here is the output:
Please enter a word: word
Are you finished: Please enter a word:
Here is my code:
#include "stdafx.h"
#include <string.h>
#define MAX 25
#define LENGTH 16
int _tmain(int argc, _TCHAR* argv[])
{
char store[MAX][LENGTH];
char word[LENGTH];
int i=0;
char exit='n';
while(exit!='y'||i==MAX)
{
printf("Please enter a word: ");
scanf("%s",&word);
printf("\n");
while(strlen(word)>15)
{
memset(word, NULL, LENGTH);
printf("You have entered a word that is to large.\n");
printf("Please enter a word: ");
scanf("%s",&word);
}
strcpy(store[i], word);
printf("Are you finished: ");
scanf("%c",&exit);
i++;
}
return 0;
}
Thank you for your help.