How can I improve/shorten my C code?
Hi everyone,
I'm still new to C, coming from a Python background, and I was wondering if you could suggest any ways to improve/shorten my code. It's for a first-year university assignment, but I've already got it working and golfed it a bit on my own. Here it is:
Code:
#include<stdio.h>
#include <ctype.h>
int main(void) {
char c = '\0';
int vowelCount = 0, conCount = 0;
while (c != '0') {
puts("\nPlease enter a letter: ");
scanf(" %c", &c);
if (isalpha(c) || c == '0') {
switch (tolower(c)) {
case '0':
puts("\nThank you for counting on me.");
continue;
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vowelCount++;
for (int i = 0; i < vowelCount; i++) {
putchar('*');
}
break;
default:
conCount++;
for (int i = 0; i < conCount; i++) {
putchar('!');
}
}
}
else {
puts("\nAny character not in the English alphabet is not an accepted input for this application.\n");
}
}
}
Any comments welcome! :D