如何在C中使用getchar函数和putchar函数?
How to use getchar function and putchar function in C?
所以我的代码读入一个词并将其显示回用户后备词。这是我的:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int i;
char word[10];
printf("Enter a six letter word: ");
for(i=0; i<6; i++){
scanf("%c", &word[i]);
}
for (i=5; i>=0; i--){
printf("%c", word[i]);
}
return 0;
}
除了使用 scanf 和 printf,我应该如何使用 getchar 和 putchar?
word[i]=getchar();
和
putchar(word[i]);
所以我的代码读入一个词并将其显示回用户后备词。这是我的:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int i;
char word[10];
printf("Enter a six letter word: ");
for(i=0; i<6; i++){
scanf("%c", &word[i]);
}
for (i=5; i>=0; i--){
printf("%c", word[i]);
}
return 0;
}
除了使用 scanf 和 printf,我应该如何使用 getchar 和 putchar?
word[i]=getchar();
和
putchar(word[i]);