Ok here is what i have so far. I have made very minor changes to the code, just that now I broke up my sorting into different categories and I am counting how many characters are in each category instead of which category the character fits. I don't think those changes are too drastic.
I have also updated my code with anduril462 suggestion.
You could also use fgets to read in your string: fgets(str, sizeof(str), stdin); reads a whole line. It also null terminates your string and makes sure you don't overflow it
The instructions I am following specifically says to use getchar() only.
I am using Microsoft Visual C++ 2010 Express and the particular error I am receiving does not tell me which line it occurs on just a window that pops up after I enter in values for my sting.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main (void)
{
char str[81];
int length, i = 0, count = 0, count_1 = 0,count_2 = 0, count_3 = 0, count_4 = 0, ch;
do
{
printf ("Input string values: ");
while ((ch = getchar()) != EOF && ch!= '\n' && i < sizeof(str))
{
str[i++] = ch;
}
length = strlen(str);
for (i = 0; i < length; i++)
{
if (isalpha(str[i]))
count++;
printf ("%i characters are alphabetic\n", count);
if (islower(str[i]))
count_1++;
printf ("%i characters are lowercase\n", count_1);
if (isupper(str[i]))
count_2++;
printf ("%i characters are uppercase\n", count_2);
if (isdigit(str[i]))
count_3++;
printf ("%i characters are numeric\n", count_3);
if (isalpha(str[i]))
count_4++;
printf ("%i characters are alphanumeric\n", count_4);
printf("\n");
}
}
while (strlen(str) > 0);
return 0;
}