02 2013 档案

摘要: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 阅读(619) 评论(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 阅读(199) 评论(0) 推荐(0)
摘要:itoa是广泛应用的非标准C语言扩展函数。由于它不是标准C语言函数,所以不能在所有的编译器中使用。但是,大多数的编译器(如Windows上的)通常在<stdlib.h>头文件中包含这个函数。在<stdlib.h>中与之有相反功能的函数是atoi。功能:把一整数转换为字符串。那么如何实现一个itoa函数呢?这个好像难度一般,我就直接附上我的实现,对此不熟悉的人最好自己code一下。atoi version one 1 /* reverse the string named s */ 2 void reverse(char s[]) 3 { 4 for(int i=0,j= 阅读全文
posted @ 2013-02-04 19:40 freewater 阅读(488) 评论(0) 推荐(0)