这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
FILE *fp;
char s[50];
fp = fopen("line.txt" , "r");
if( fgets (s, 50, fp)!=NULL )
{
puts(s);
}
fclose(fp);
return 0;
}
我知道如何使用 printf 函数以所有大写和小写字母显示字符串。但我不知道如何使用 fgets 函数来完成。我也在从文件中读取字符串,所以这对我来说是一件棘手的事情。
最佳答案
if( fgets (s, 50, fp)!=NULL )
{
for( size_t ii = 0; s[ii]; ii++ )
{
s[ii] = toupper((unsigned char)s[ii]);
}
puts(s);
}
关于c - 如何严格使用 fgets 函数以大写/小写字母打印字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36758722/