/* io.c Started by Jeff Ondich at the dawn of time. Last modified 4/1/97 This program provides a very brief introduction to input and output in C. 0. Compile and run this program. 1. What happens if you type two characters in response to the first request? What if you just hit the return key? 2. When scanf is looking for a string, what does it do with newlines? How does it decide where the string begins and where the string ends? 3. What does the for-loop "Another way..." tell you about how strings are stored in C? 4. What happens if you don't type an integer in response to the request for an integer? */ #include void main( void ) { int i; char c, charArray[100]; /* Getting a character... */ printf( "Type a character: " ); c = getchar(); /* and sending it back. */ printf( "Your character was: " ); putchar( c ); putchar( '\n' ); /* A more common way of performing that output. */ printf( "Your character was: %c\n\n", c ); /* Getting a string and sending it back. */ printf( "Type a string, please: " ); scanf( "%s", charArray ); printf( "Your string was: %s\n", charArray ); /* Another way of sending back the string. */ printf( "Your string was: " ); for( i=0; charArray[i] != '\0'; i=i+1 ) putchar( charArray[i] ); /* Getting an integer and sending it back. */ printf( "\n\nType an integer, please: " ); scanf( "%d", &i ); printf( "Your integer was %d\n", i ); printf( "In base eight (octal), that's %o\n", i ); }