Created
July 15, 2010 21:53
-
-
Save rchowe/477582 to your computer and use it in GitHub Desktop.
globvar.c
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
char name[15]; | |
static void name_prompt( char *buffer, size_t len ); | |
static void intro(); | |
int main( void ) | |
{ | |
// Zero the name array | |
memset( name, 0, 15 * sizeof(char)); | |
// Call the intro function | |
intro(); | |
printf( "Having the name %s makes you special.\n", name ); | |
} | |
static void intro() | |
{ | |
printf( "You wake up. The only thing you can remember is your name. What is it? " ); | |
name_prompt( name, 15 ); | |
printf( "Yes, %s, you were born into an amazing position.\n", name ); | |
} | |
static void name_prompt( char *buffer, size_t len ) | |
{ | |
int i = 0; | |
while ( i < len ) | |
{ | |
char c = getchar(); | |
if ( c == '\n' || c == EOF ) | |
break; | |
buffer[i] = c; | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment