1. 程式人生 > >實現一個函式,把一個字串中的字元從小寫轉為大寫。

實現一個函式,把一個字串中的字元從小寫轉為大寫。

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void upper(char* s, char* us)
{
    while(*s != '\0')
    {
        if(*s >= 'a' && *s <= 'z')
        {
            *us = *s - 32;
        }
        else
        {
            *us = *s;
        }
        s++;
        us++;
    }
    *us
= '\0';//注意不要漏了這一句 } int main() { char A[20],B[20]; printf("Please input a string:\n"); scanf_s("%s", A, 20); upper(A,B); printf("%s", B); printf("%c", A[19]);//A[19]存的是'\0' }