gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:38:41 24 4
gpt4 key购买 nike

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

#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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com