Skip to content

Instantly share code, notes, and snippets.

@rchowe
Created July 15, 2010 21:53
Show Gist options
  • Save rchowe/477582 to your computer and use it in GitHub Desktop.
Save rchowe/477582 to your computer and use it in GitHub Desktop.
globvar.c
#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