Created
October 31, 2010 20:02
-
-
Save Cellane/657061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// charStats.c | |
// Zkouska | |
// | |
// Created by Milan Vít on 31. 10. 10. | |
// Copyright (c) 2010 Ostravská univerzita v Ostravě. All rights reserved. | |
// | |
#include <stdio.h> | |
#include "charStats.h" | |
int numberOfLowerCase = 0; | |
int numberOfUpperCase = 0; | |
int numberOfOtherChars = -1; // user input will end up with zero | |
// but we don't want to count that towards the results | |
char readCharacter () { | |
printf ("Enter a char: "); | |
return (getchar ()); | |
} | |
void addToStats (char character) { | |
if (character >= 'a' && character <= 'z') { | |
numberOfLowerCase++; | |
} else if (character >= 'A' && character <= 'Z') { | |
numberOfUpperCase++; | |
} else { | |
numberOfOtherChars++; | |
} | |
} | |
void printStats () { | |
printf ("Number of lower-case letters: %d.\n", numberOfLowerCase); | |
printf ("Number of upper-case letters: %d.\n", numberOfUpperCase); | |
printf ("Number of other letters: %d.\n", numberOfOtherChars); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// charStats.h | |
// Zkouska | |
// | |
// Created by Milan Vít on 31. 10. 10. | |
// Copyright (c) 2010 Ostravská univerzita v Ostravě. All rights reserved. | |
// | |
#ifndef CHARSTATS_H | |
#define CHARSTATS_H | |
char readCharacter (); | |
void addToStats (char); | |
void printStats (); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.c | |
// Zkouska | |
// | |
// Created by Milan Vít on 31. 10. 10. | |
// Copyright (c) 2010 Ostravská univerzita v Ostravě. All rights reserved. | |
// | |
#include <stdio.h> | |
#include "charStats.h" | |
int main (int argc, const char *argv[]) { | |
char character; | |
do { | |
character = readCharacter (); | |
addToStats (character); | |
} while (character != '0'); | |
printStats (); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment