Newbie - about using toupper/tolower

Discussion in 'C Programming' started by Randy Rieger, Jul 7, 2003.

  1. Randy Rieger

    Randy Rieger Guest

    Background: I use DJGPP with these arguments to make sure its standard C
    -ansi -W -Wall -pedantic

    I have a simple script (below).

    My problem is everytime I compile it, it gives a warning saying 'implicit
    declaration of function 'toupper', and again for tolower. I don't
    understand what I'm doing wrong. Can someone help me :)



    #include <stdio.h>
    /*We need to include this header file in order to use the functions below*/
    #include <string.h>
    #include <stdlib.h>


    int main()
    {
    char first[20], second[20];
    int x;

    printf("Enter first string: ");
    scanf("%s",first);
    printf("Enter second string: ");
    scanf("%s", second);
    /* change case of string to 'UPPER CASE'
    - some would like to use strupr(), but this isn't Standard C. So...
    we use a loop to run through all the characters in our string, using
    toupper()
    on each one */

    for (x=0; x<strlen(first); ++x)
    {
    first[x] = toupper(first[x]);
    }

    printf("Now let's convert the first string to upper case!\n");


    printf("We get: %s\n\n", first);

    printf("first is now %s\nsecond is now %s\n\n", first, second);



    /* change case of string to 'lower case'
    - some would like to use strlwr(), but this isn't Standard C. So...
    we use a loop to run through all the characters in our string, using
    tolower()
    on each one */

    for (x=0; x<strlen(first); ++x)
    {
    first[x] = tolower(first[x]);
    }

    printf("and back to lower case: %s\n\n", first);

    printf("first is now %s\nsecond is now %s\n\n", first, second);


    return 0;
    }
     
    Randy Rieger, Jul 7, 2003
    #1
    1. Advertising

  2. "Randy Rieger" <> wrote in message
    news:cE4Oa.76631$...
    >
    > I have a simple script (below).
    >
    > My problem is everytime I compile it, it gives a warning saying 'implicit
    > declaration of function 'toupper', and again for tolower.
    >
    > #include <stdio.h>
    > /*We need to include this header file in order to use the functions
    > below*/
    > #include <string.h>
    > #include <stdlib.h>
    >
    > int main()


    You need to #include <ctype.h> to get the function prototypes for toupper
    and tolower.

    Regards,

    Russell Hanneken
     
    Russell Hanneken, Jul 7, 2003
    #2
    1. Advertising

  3. Randy Rieger

    Randy Rieger Guest

    thanks for both your answers guys. Well detailed, I learned something today
    :)
     
    Randy Rieger, Jul 7, 2003
    #3
  4. Randy Rieger

    Randy Rieger Guest

    thanks for both your answers guys. Well detailed, I learned something today
    :)
     
    Randy Rieger, Jul 7, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp

    tolower used by transform

    qazmlp, Jul 22, 2003, in forum: C++
    Replies:
    3
    Views:
    3,456
    Sergei Matusevich
    Jul 23, 2003
  2. David Rubin

    tolower conflict with iostream?

    David Rubin, Oct 8, 2003, in forum: C++
    Replies:
    13
    Views:
    715
    tom_usenet
    Oct 14, 2003
  3. TheDD
    Replies:
    11
    Views:
    7,030
    Klaus Eichner
    May 29, 2004
  4. Roman Mashak

    tolower() and toupper()

    Roman Mashak, Nov 1, 2006, in forum: C Programming
    Replies:
    8
    Views:
    495
    CBFalconer
    Nov 2, 2006
  5. Eric Lilja
    Replies:
    4
    Views:
    453
    Thierry Miceli
    Sep 2, 2005
Loading...

Share This Page