pszBuf为字符串指针,用C语言实现将该字符串中的所有小写字符'a'-'z'转换为大写字符。

代码中不得调用任何C标准库函数
C语言小白 求解答。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

参看下面代码:
void
test(unsigned char *pszBuf)
{
unsigned char *p;
unsigned char delta;

if(!pszBuf) {
    goto out;
}

delta = 'a' - 'A';
p = pszBuf;
while(*p != '\0') {
    if(*p >= 'a' && *p <= 'z') {
        *p -= delta;
    }
    p ++;
}

out:
return;
}


#include <string.h>
 void foo(char *pszBuf)
{
    int n = strlen(pszBuf);
    for (int i = 0; i < n; i++)
    {
        if (pszBuf[i] >= 'A' && pszBuf[i] <= 'Z') pszBuf[i] = pszBuf[i] - 'a' + 'A';
    }
}
 void foo(char *pszBuf)
{
    int n = strlen(pszBuf);
    for (int i = 0; i < n; i++)
    {
        if (pszBuf[i] >= 'a' && pszBuf[i] <= 'z') pszBuf[i] = pszBuf[i] - 'a' + 'A';
    }
}
 void foo(char *pszBuf)
{
    int n = 0;
        while (pszBuff[++n]);
    for (int i = 0; i < n; i++)
    {
        if (pszBuf[i] >= 'a' && pszBuf[i] <= 'z') pszBuf[i] = pszBuf[i] - 'a' + 'A';
    }
}
 void fun(char *pszBuf)
{

    while (*pszBuf)
    {
        if (*pszBuf >= 'a' && *pszBuf <= 'z') *pszBuf = *pszBuf - 'a' + 'A';
        pszBuf++;
    }
}

这个涉及到字符串的处理,需要注意的一点是待处理的字符串一定要先赋予一个地址,否则即使修改字符串的函数对,也未必能够完成转换,

void change(char *str){
char *p = str;
while(*p!='\0'){
if(*p>='a' && *p<='z'){
printf("%c\n",*p);
*p= *p - 'a' + 'A';
}
p++;
}
}

int main()
{

char *str = (char *)malloc(sizeof(char)*50);
char *p = "school",*tempstr=str;/*  p为需要修改的字符串  */
while(*p!=NULL){
    *(tempstr++)=*p++;
}
*tempstr='\0';/*  为str添加字符结束符  */
printf("%s\n",str);
change(str);
printf("%s\n",str);
return 0;

}

void foo(char *pszBuf)
{
int n = strlen(pszBuf);
for (int i = 0; i < n; i++)
{
if (pszBuf[i] >= 'a' && pszBuf[i] <= 'z') pszBuf[i] = pszBuf[i] - 'a' + 'A';
}
}