putchar()
code:
#include <stdio.h>
int main ()
{
char ch;
for(ch = 'A' ; ch <= 'Z' ; ch++) {
putchar(ch);
printf("\n");
}
return(0);
}
screen:
把getchar()理解为专门用于键入字符串的scanf(),
putchar()是专门用于输出字符串的printf()
补充:从文件中获取字符
code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<math.h>
//试试用fgectc()从文件中打印字符数据
int main()
{
FILE*fp;
fp = fopen("test.txt","r");
char ch;
while(!feof(fp))
{
ch = fgetc(fp);
putchar(ch);
printf(" ");
}
return 0;
}
screen:
dev无法识别文件中的中文,故显示乱码。