char dict[N][M];
for(i = 0; i < N; i++)
{
do
{
printf("enter word at position: %d\n", i);
gets(dict[i]);
printf("you entered %s\n", dict[i]);
if(isalnum(dict[i]))
{
printf("error\n");
}
}while (isalnum(dict[i]));
}
Hello I’m new to C and I want to do validation with isalnum but with a 2d array
for example if dict[0][80] is non alphanumeric the user enter again.
Thanks
Your compiler should print a warning similar to this when you try to compile your code:
This warning is a sign that the code isn’t doing what you want, and here’s why. The signature of the “isalnum” function is
int isalnum(int c)which means it takes an integer (i.e. character) argument; however, you’re calling it with the argumentdict[i], which is achar *(a pointer to a character, e.g. a string).I’m guessing what you want to do is check that each character in the string is alphabetic or numeric. Try replacing your call to “isalnum” with your own function like so: