一 c读取一行字符串
1 gets
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int size = 1024;
char* buff = (char*)malloc(size);
// read lines
while(NULL != gets(buff)){
printf("Read line with len: %dn", strlen(buff));
printf("%s", buff);
}
// free buff
free(buff);
}
利用getchar()读取一个个字符来读取一行
#include <stdio.h>
#include <stdlib.h>
int my_getline(char* line, int max_size)
{
int c;
int len = 0;
while( (c = getchar()) != EOF && len < max_size ){
line[len++] = c;
if('n' == c)
break;
}
line[len] = '