Hello there. This is just part of error checking in a much larger program, where I have to use only getchar (if even) / gets to manipulate the array to only store uppercase A-Z characters, with min number of characters being 2, max 10. I guess I'm still not comfortable using these functions. No string library functions may be use. What I have so far is below. Any help would be highly appreciated, thanks in advance.
Code:
#include <stdlib.h>
#include <stdio.h>
int main()
{
char string[11]; /* gets will replace newline with null, so don't have to initialize
string[10] to null*/
int iochar;
printf("Input string with uppercase A-Z characters, min 2 max 10:\n");
while(iochar = getchar())
{
if(iochar >= 'A' && iochar <= 'Z')
{
gets(string);
}
}
puts(string); /* testing string */
}
What I have above doesn't do anything, I was just messing around with getchar and such. I tried to set the while loop as while(iochar = getchar() != '\n'), but that gave me some erroneous results. I've also tried setting an if statement to check for lowercase characters, and a printf call to tell the user that the string can't be lowercase, but it would be print that statement (can't be lowercase) every time a single lower case is found. This is just one part of my program that I can't seem to figure out...