我是C的新手。现在尝试练习输入和输出。我正在尝试使用fgets读取句子并将其转换为所有大写字母,但由于某种原因,它无法阅读。我在我的扫描仪中添加了* 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;
}
}