【发布时间】:2021-12-29 21:57:57
【问题描述】:
好的,所以我一直在处理 fscanf 代码,但遇到了一个问题。那么当我们使用转换为大写时我们使用什么?我的代码在这里:
#include <stdio.h>
#include <string.h>
int main() {
FILE* input_file = fopen("file1.txt","r");
if (input_file == NULL){
printf("Unable to open input file\n");
return 1;
}
char line[1000];
while( fgets(line, 1000, input_file) != NULL ){
//maybe
int length = strlen(line);
if (line[length-1] == '\n'){
line[length-1] = '\0';
}
//
for(int i = 0; line[i] != '\0'; i++){
if (line[i] == '\n'){
line[i] = '\0';
}
}
printf("%c\n", toupper(line*));
}
fclose(input_file);
input_file = NULL;
return 0;
}
我尝试过使用 toupper 但不起作用...我拥有的文本文件是:
Tomorrow, and tomorrow, and tomorrow,
Creeps in this petty pace from day to day,
To the last syllable of recorded time;
And all our yesterdays have lighted fools
The way to dusty death. Out, out, brief candle!
Life's but a walking shadow, a poor player
That struts and frets his hour upon the stage
And then is heard no more. It is a tale
Told by an idiot, full of sound and fury
Signifying nothing.
我能够复制但我不知道如何让它大写....还有谁能告诉我你会如何输入总单词字符和字母字符?因为我想看看它是如何工作的……目前我收到的是enter image description here
【问题讨论】:
-
同理,要求文本文件中的所有单词都变成大写字母
-
将
printf("%c\n", toupper([i]));放入 for(int i...) 循环中 -
请将错误发布为文本而不是屏幕截图。图像显示
line*上的语法错误。toupper()需要int,而line是char *,所以第一个字母是*line或line[0]。它的格式很差,很难阅读。您已经找到每个单词的第一个字母,然后将其添加。strsep()可能会有所帮助。 -
你能告诉我你是怎么做到的吗?我很困惑