您的位置:首页 > 其它

atoi、itoa,strcpy,strcmp,memcpy等实现

2012-06-05 15:43 411 查看
1、memcpy、memmove、memset源码

link:http://note.youdao.com/share/?id=1f826e4337c7db272e94fdb4f267a8de&type=note

2、strcpy、strcat等源码

link:http://note.youdao.com/share/?id=d23a598b2e31321517ed57d2599de181&type=note

3、atoi和itoa源码:

link:http://note.youdao.com/share/?id=96b713b249981aa0c5f9be5d0657fb90&type=note

[b]整数字符串的转化[/b]

1、直接采用现有函数

(1)直接采用itoa实现整数到字符串的转换

  函数形式为: char *itoa(int value, char *string, int radix);

  该函数包含在头文件stdlib.h中。int value 被转换的整数,char *string 转换后储存的字符数组,int radix 转换进制数,如2,8,10,16 进制等。

  具体实现为:

View Code

#include<stdio.h>
#include<string.h>
#define max 100
void main()
{
int i,len,offset=0,count=1;
char str[max];
char temp[max];
printf("please input the string");
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i+1]==str[i])
{
count++;
}
else
{
offset+=sprintf(temp+offset,"%c%d",str[i],count);
count=1;
}
}
temp[offset]='\0';
printf("the result is:  %s",temp);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: