c - c 中的 fgets() 根本不读句子?
问题描述
我对C非常陌生。现在尝试练习输入和输出。我正在尝试使用 fgets 阅读一个句子并将其转换为所有大写字母,但由于某种原因它没有阅读它。我在我的 SCANF 中添加了 *c,但它仍然不起作用。非常感谢任何建议和提示!提前致谢。
#include <stdio.h>
#include <ctype.h>
#define ARR_SIZE 100
void modify(int pInt[100], int input);
void modify2(char *pString[100]);
int main() {
printf("Enter a size for your array:\n");
int input;
scanf("%d", &input);
printf("Great! You now have an array of size %d.\n", input);
int array[ARR_SIZE];
printf("Now please enter %d numbers.\n", input);
int i;
for (i = 0; i < input; i++) {
scanf("%d*c", &array[i]);
}
printf("Awesome. All %d slots in the array are now filled.\n", input);
printf("Here is how your array looks:\n");
int j;
for (j = 0; j < input; j++) {
printf(" %d |", array[j]);
}
printf("\n");
modify(array, input);
printf("Now your array looks like this:\n");
for (j = 0; j < input; j++) {
printf(" %d |", array[j]);
}
printf("\n");
printf("Experiment #2:\n");
printf("Enter a sentence:\n");
char sentence[ARR_SIZE];
fgets(sentence, ARR_SIZE, stdin);
modify2(sentence);
printf("Now your sentence is upper case: %s\n", sentence);
return 0;
}
void modify2(char *pString[100]) {
int i = 0;
while (pString[i]) {
pString[i] = toupper(pString[i]);
i++;
}
}
void modify(int pInt[100], int input) {
int i;
for (i = 0; i < input; i++) {
pInt[i] *= 2;
}
}
解决方案
推荐阅读
- javascript - 如何将新创建的 jsPdf 文件上传到服务器而不是保存在本地计算机中?
- sql - SAP HANA 的 := 语法有什么作用?
- python - 函数只需要 2 个参数(给定 4 个)
- angular - 带有子路由的 Angular 将子组件加载到父组件下方,而不是将其重定向到另一个视图
- macos - 为什么 Visual Studio 找不到我的程序集?
- python - 除非主窗口未聚焦,否则不会更新 QLabel
- ios - Swift:在没有键盘滑块的情况下关闭 ViewController
- r - RSelenium rsDriver 给出错误 can't kill an exited process
- xslt - 通过 XSL 匹配 XML 中的特定元素
- embedded - STM32F107 通过 SPI 从外部 Flash 启动