摘要: getline is to read a line of characters from input stream.My naive implement as follows, 1 #include<stdio.h> 2 3 /* getline: get line into s, return length. 4 arguments: lim is the max length of s. 5 */ 6 int getline(char s[],int lim) 7 { 8 int c;//store character acquired from input stream. 9 阅读全文
posted @ 2013-02-05 12:16 freewater 阅读(606) 评论(0) 推荐(0) 编辑
摘要: 简洁的atoi 1 #include<ctype.h> //isspace and isdigit 2 3 /* convert string to integer */ 4 int atoi(char s[]) 5 { 6 int i,n,sign; 7 for(i=0;isspace(s[i]);i++)//skip white space 8 ; 9 sign=(s[i]=='-')?-1:1;10 if(s[i]=='+'||s[i]=='-')//skip sign11 i++;12 for(n=0;isdig... 阅读全文
posted @ 2013-02-05 10:51 freewater 阅读(190) 评论(0) 推荐(0) 编辑