toupper函数及一些小程序

时间:2023-12-30 19:28:50

 toupper

   原型:extern int toupper(int c);

   用法:#include <ctype.h>

   功能:将字符c转换为大写英文字母

   说明:如果c为小写英文字母,则返回对应的大写字母;否则返回原来的值。

   举例:

       // toupper.c

       #include <syslib.h>
#include <ctype.h> main()
{
char *s="Hello, World!";
int i; clrscr(); // clear screen
printf("%s\n",s);
for(i=;i<strlen(s);i++)
{
putchar(toupper(s[i]));
} getchar();
return ;
}
//---------------------------------1
#include <stdio.h>
#include<stdlib.h>
void main()
{
printf("0 & 0 is %d\n", & );
printf("0 & 1 is %d\n", & );
printf("1 & 1 is %d\n", & );
printf("1 & 2 is %d\n", & );
printf("15 & 127 is %d\n", & );
system("pause");
}
//------------------------------2
#include <stdio.h>
#include<stdlib.h>
void main()
{
int value = 0xFF; printf("The inverse of %X is %X\n", value, ~value);
system("pause");
}
//-------------------------------3
#include <stdio.h>
#include<stdlib.h>
void main()
{
printf("0 | 0 is %d\n", | );
printf("0 | 1 is %d\n", | );
printf("1 | 1 is %d\n", | );
printf("1 | 2 is %d\n", | );
printf("128 | 127 is %d\n", | );
system("pause");
}
//------------------------------------4
#include <stdio.h>
#include<stdlib.h>
void main()
{
printf("0 ^ 0 is %d\n", ^ );
printf("0 ^ 1 is %d\n", ^ );
printf("1 ^ 1 is %d\n", ^ );
printf("1 ^ 2 is %d\n", ^ );
printf("15 ^ 127 is %d\n", ^ );
system("pause");
}
//------------------------------------5
#include <stdio.h>
#include<stdlib.h>
void main()
{
printf("The letter is %c\n", 'A');
printf("The letter is %c\n", );
system("pause");
}
//---------------------------------------6
#include <stdio.h>
#include<stdlib.h>
void main()
{
char letter; int vowel_count = ;
int consonant_count = ; for (letter = 'A'; letter <= 'Z'; letter++)
switch (letter) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': vowel_count++;
break;
default: consonant_count++;
}; printf("The number of vowels is %d\n", vowel_count);
printf("The number of vowels is %d\n", consonant_count);
system("pause");
}
//------------------------------------------------------------7
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h> void main()
{
char letter; do {
printf("A Display directory listing\n");
printf("B Display disk information\n");
printf("C Change system date\n");
printf("Q Quit\n");
printf("Choice: "); letter = getchar();
letter = toupper(letter); if (letter == 'A')
system("DIR");
else if (letter == 'B')
system("CHKDSK");//不能用
else if (letter == 'C')
system("DATE");
} while (letter != 'Q');
system("pause");
}