Added files from first programming course at OSU

This commit is contained in:
2019-07-09 18:14:25 -07:00
parent 4a591de966
commit 8c92e250d9
48 changed files with 2858 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
/*
* Original Author: Corwin A. Perren (perrenc)
* File: flush.c
* Created: 2012 February 16, 03:11 by perrenc
* Last Modified: 2012 February 16, 03:11 by perrenc
*
* Has the user input some text, prints out the first character entered along with its
* ascii code and then reruns until it receives a "%" character.
*
*/
#include <stdio.h>
/* ------Begin Functions------ */
/*Has the user input text, uses getchar to store the first character, then loops through
* getchar until the buffer is clear when it receives a "\n". */
char getchar_and_flush(){
char foo; //Used for temp user input storage
int loop; //Used for looping to clear the buffer
printf("Please enter some text. Press enter to finish. To quit, type a \"%\" symbol. ");
foo = getchar ();
loop = foo;
while(loop != '\n'){
loop = getchar ();
}
return foo;
}
/* ------End Functions------ */
/* Initalizes foo, clears the screen, then calls getchar_and_flush until the return
* character is "%" */
int main(int argc, char **argv){
char foo; //Used to check the return value of getchar_and_flush for looping
system("clear");
while(foo != '%'){
foo = getchar_and_flush();
printf("\nThe first character was %c or %d in ASCII.\n\n", foo, foo);
}
return 0;
}