Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created January 10, 2012 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/1586601 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/1586601 to your computer and use it in GitHub Desktop.
Learn C the Hard Way Example 13
#include <stdio.h>
int main(int argc, char *argv[])
{
if(2 != argc)
{
printf("ERROR: You need one argument.\n");
return 1;
}
int i;
char letter;
for(i = 0, letter = argv[1][i]; '\0' != argv[1][i]; i++, letter = argv[1][i])
{
switch(letter)
{
case 'a':
case 'A':
printf("%d: 'A'\n", i);
break;
case 'e':
case 'E':
printf("%d: 'E'\n", i);
break;
case 'i':
case 'I':
printf("%d: 'I'\n", i);
break;
case 'o':
case 'O':
printf("%d: 'O'\n", i);
break;
case 'u':
case 'U':
printf("%d: 'U'\n", i);
break;
case 'y':
case 'Y':
if(i > 2)
printf("%d: 'Y'\n", i);
break;
default:
printf("%d: %c is not a vowel\n", i, letter);
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment