c - 如何在此代码中使用函数 toupper() ?

标签 c

我想把我写的内容变成大写。但我不知道该怎么做。 这是我的代码:

#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>

int main(){
        char buffer[50];
        int retorno, leido, c; 
        while( (leido = read(0,&buffer,sizeof buffer)) > 0){
                retorno = write(1,&buffer,leido);
        }
        printf ("valor de retorno: %d\n", retorno);
        if (retorno<0){
                return -1;
        } 
        return 0; 
}

最佳答案

您需要toupper每个字符,例如

while( (leido = read(0,&buffer,sizeof buffer)) > 0){
   for (int i=0; i<leido; i++) {
      buffer[i] = toupper((unsigned char)buffer[i]);
   }
   retorno = write(1,&buffer,leido);
}

关于c - 如何在此代码中使用函数 toupper() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49741894/

相关文章:

ios - iOS 上的 SSL 连接错误

c - 为什么我会收到错误 "Segmentation fault (core dumped)"?

c - 为什么 USART2 发送垃圾值?

c - 使用 Park&Miller RNG 制作大样本?

c - 使用指针获取 uint16_t 的 8 位单独地址

c++ - 如何为 C 脚本配置 lighttpd 和 fcgi?

c - 以格式化形式打印结果

转换返回浮点类型的函数的返回值

C 图片库

c - 从另一个线程杀死一个线程