Newbie - about using toupper/tolower

R

Randy Rieger

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;
}
 
R

Russell Hanneken

Randy Rieger said:
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
(e-mail address removed)
 
R

Randy Rieger

thanks for both your answers guys. Well detailed, I learned something today
:)
 
R

Randy Rieger

thanks for both your answers guys. Well detailed, I learned something today
:)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top