题:时间字符串YYYY-[m]m-[d]d转换为int类型,例如 2014-10-17 转换为20141017
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// delete the char c in s[];
void my_squeeze(char *s,int c)
{
int i,j,len;
len=strlen(s);
for(i=0,j=0;i!=len;i++)
if(s[i]!=c)
<span style="white-space:pre"> </span> s[j++]=s[i];
s[j]='\0';
}
//字符转换为整数,不用atoi
int my_atoi(char *s)
{
<span style="white-space:pre"> </span>int i,sum=0;
if(s!=NULL)
<span style="white-space:pre"> </span> for(i=0;i!=strlen(s);i++)
<span style="white-space:pre"> </span> sum=sum*10+s[i]-'0';
return sum;
}
void main()
{
char s[]="agg";
char time[]="2014-01-17";
my_squeeze(s,'g');
my_squeeze(time,'-');
printf("%s\n",s);
printf("%s\n",time);
printf("%d\n",atoi(time));
printf("%d\n",my_atoi(time));
system("pause");
}