implicit declatation of function 'int toupper(...)'

This is a discussion on implicit declatation of function 'int toupper(...)' within the C Programming forums, part of the General Programming Boards category; WTF does this mean it's pointing to this code... //Michael Handlon //Project 4 #include <stdio.h> int answer = 0; char ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    46

    Unhappy implicit declatation of function 'int toupper(...)'

    WTF does this mean it's pointing to this code...

    //Michael Handlon
    //Project 4

    #include <stdio.h>

    int answer = 0;

    char num1;
    int tmp1 = 0;

    char oper;

    char num2;
    int tmp2 = 0;

    int main(void){
    printf("Input your first Roman Numeral (1 @ a time; # to quit) ");


    while((num1 = getchar()) != '#'){

    switch( toupper( num1 ) ){ // says error is on this line.

    case 'I':
    tmp1 = tmp1 + 1;
    break;

    case 'V':
    tmp1 = tmp1 + 5;
    break;

    case 'X':
    tmp1 = tmp1 + 10;
    break;

    case 'L':
    tmp1 = tmp1 + 50;
    break;

    case 'C':
    tmp1 = tmp1 + 100;
    break;

    case 'D':
    tmp1 = tmp1 + 500;
    break;

    case 'M':
    tmp1 = tmp1 + 1000;
    break;

    case '#':
    printf("Quit then.");
    break;

    default:
    printf("WTF are you doing?");
    break;
    } // end switch
    } // end while

    printf("What kind of operator would you like to use('+', '-', '*', '/'?): ");
    oper = getchar();


    printf("Input your second Roman Numeral (1 @ a time; # to quit) ");

    while((num2 = getchar()) != '#'){

    switch( toupper( num2 ) ){

    case 'I':
    tmp2 = tmp2 + 1;
    break;

    case 'V':
    tmp2 = tmp2 + 5;
    break;

    case 'X':
    tmp2 = tmp2 + 10;
    break;

    case 'L':
    tmp2 = tmp2 + 50;
    break;

    case 'C':
    tmp2 = tmp2 + 100;
    break;

    case 'D':
    tmp2 = tmp2 + 500;
    break;

    case 'M':
    tmp2 = tmp2 + 1000;
    break;

    case '#':
    printf("Quit then.");
    break;

    default:
    printf("WTF are you doing?");
    break;
    } //end switch
    } //end while


    if (oper == '+'){
    answer = tmp1 + tmp2;
    }

    if (oper == '-'){
    answer = tmp1 - tmp2;
    }

    if (oper == '*'){
    answer = tmp1 * tmp2;
    }

    if (oper == '/'){
    answer = tmp1 / tmp2;
    }

    printf("Your answer is %d.",answer);

    return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    46
    //Michael Handlon
    //Project 4

    #include <stdio.h>
    #include <ctype.h>

    int answer = 0;

    char num1;
    int tmp1 = 0;

    char oper;

    char num2;
    int tmp2 = 0;

    int main(void){
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    while((num1 = getchar()) != '#'){


    switch( toupper( num1 ) ){

    case 'I':
    tmp1 = tmp1 + 1;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'V':
    tmp1 = tmp1 + 5;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'X':
    tmp1 = tmp1 + 10;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'L':
    tmp1 = tmp1 + 50;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'C':
    tmp1 = tmp1 + 100;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'D':
    tmp1 = tmp1 + 500;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'M':
    tmp1 = tmp1 + 1000;
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
    break;

    case '#':
    printf("\nQuit then.");
    break;

    } // end switch
    } // end while

    printf("\nWhat kind of operator would you like to use('+', '-', '*', '/'?): ");
    oper = getchar();

    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    while((num2 = getchar()) != '#'){

    switch( toupper( num2 ) ){

    case 'I':
    tmp2 = tmp2 + 1;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'V':
    tmp2 = tmp2 + 5;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'X':
    tmp2 = tmp2 + 10;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'L':
    tmp2 = tmp2 + 50;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'C':
    tmp2 = tmp2 + 100;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'D':
    tmp2 = tmp2 + 500;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case 'M':
    tmp2 = tmp2 + 1000;
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    case '#':
    printf("\nQuit then.");
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
    break;

    } //end switch
    } //end while


    if (oper == '+'){
    answer = tmp1 + tmp2;
    }

    if (oper == '-'){
    answer = tmp1 - tmp2;
    }

    if (oper == '*'){
    answer = tmp1 * tmp2;
    }

    if (oper == '/'){
    answer = tmp1 / tmp2;
    }

    printf("\nYour answer is %d.",answer);

    return 0;
    }



    Any idea why this compiles yet hangs after you add an operator?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    As for your char oper; instead of using " + - * / " say something like.....this compiles and runs...
    Code:
    printf("Enter mode of operation"
              " A for add, S for subtract"
              "M for multiply, D for divide");
    oper = toupper(getch());
    
    switch (oper) {
          case A: /*now perform add */
                 break;
          case S: /*perform subtract */
          /*same with multiply and divide  */
    I have compiled your program using my way and it compiles and runs....minor alterations....user inputs operation after second roman numerals....and no need for variable char oper.
    pm me for full code
    Last edited by bigtamscot; 10-01-2001 at 02:25 PM.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    247

    revised code

    too long for pm...here it is then.....

    Code:
    #include <stdio.h> 
    #include <ctype.h>
    #include <conio.h>  /*for getch() fn  */
    
    int main(void)
    {
    int answer = 0; 
    char num1;
    int tmp1 = 0;
    char num2;
    int tmp2 = 0;
    
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    
    /*NOTICE use of getch as defined in conio.h*/
    
    while((num1 = getch()) != '#'){ 
    
    
    switch( toupper( num1 ) ){ 
    
    case 'I': 
    tmp1 = tmp1 + 1; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'V': 
    tmp1 = tmp1 + 5; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'X': 
    tmp1 = tmp1 + 10; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'L': 
    tmp1 = tmp1 + 50; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'C': 
    tmp1 = tmp1 + 100; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'D': 
    tmp1 = tmp1 + 500; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'M': 
    tmp1 = tmp1 + 1000; 
    printf("\nInput your first Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case '#': 
    printf("\nQuit then."); 
    break; 
    
    } // end switch 
    } // end while
    
    /* NOTICE    */
    /*input of operation moved to after second roman input*/
    
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    
    /*NOTICE use of getch as defined in conio.h*/
    
    while((num2 = getch()) != '#'){ 
    
    switch( toupper( num2 ) ){ 
    
    case 'I': 
    tmp2 = tmp2 + 1; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'V': 
    tmp2 = tmp2 + 5; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'X': 
    tmp2 = tmp2 + 10; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'L': 
    tmp2 = tmp2 + 50; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'C': 
    tmp2 = tmp2 + 100; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'D': 
    tmp2 = tmp2 + 500; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case 'M': 
    tmp2 = tmp2 + 1000; 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    case '#': 
    printf("\nQuit then."); 
    printf("\nInput your second Roman Numeral (1 @ a time; # to quit) "); 
    break; 
    
    } //end switch 
    } //end while 
    
    /*NOTICE  HERE is operation input  */
    
    printf("Enter mode of operation"
              " A for add, S for subtract"
             "M for multiply, D for divide");
    
    /*NO NEED FOR oper TOUPPER AND GETCH fn take care*/
    /*of user input*/
      switch(toupper(getch()))
      {
        case 'A': answer = tmp1 + tmp2;/*now perform add */
                 break;
        case 'S': answer = tmp1 - tmp2;/*perform subtract */
                 break;
        case 'M': answer = tmp1 * tmp2;/*now multiply*/
                 break;
        case 'D': answer = tmp1 / tmp2; /*finally divide*/
       }
    printf("\nYour answer is %d.",answer);
    
    return 0; 
    }
    Last edited by bigtamscot; 10-01-2001 at 03:12 PM.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 05:40 PM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21