/*只用getchar函数读入一个整数,假设它单独占据一行 读到行末为止,包括换行符,输入的数保证可以存到int中 **auhtor:@zk **date:2017 2 21 *///getchar每次只可以读取一个字符,返回的是一个Int类型的数值,//即该字符的ASCII码 #include <stdio.h>#include <stdlib.h>/* run this PRogram using the console pauser or add your own getch, system("pause") or input loop */#define N 100int main(int argc, char *argv[]) {int i;i=0;char a[N];char ch;for(ch;ch = getchar();ch != EOF){if(ch != '/n'){a[i++]= ch;}else{break;}}i= atoi(a);//atoi()将字符串转换为数字,在stdlib中 printf("%d",i); return 0;}