Uses an external variable - C Function

C examples for Function:Global Variable

Description

Uses an external variable

Demo Code

#include <stdio.h>

int units = 0;         /* an external variable      */
void critic(void);

int main(void){
    extern int units;  /* an optional redeclaration */
    /*from w  w w  . j  a  v  a 2  s  .  c  om*/
    printf("How many pounds to a firkin of butter?\n");
    scanf("%d", &units);
    while ( units != 56)
        critic();
    printf("You must have looked it up!\n");
    
    return 0;
}

void critic(void){
    /* optional redeclaration omitted */
    printf("No luck, my friend. Try again.\n");
    scanf("%d", &units);
}

Related Tutorials