【C语言】【面试题】【笔试题】模拟实现strncpy
2016-05-30 15:03
1056 查看
#include <stdio.h> #include <stdlib.h> #include <assert.h> char *my_strncpy(char *dest,const char *src, int len) { char *ret = dest; while (len--) { *dest++ = *src++; } *dest = '\0'; return ret; } int main() { char arr1[20] = "hello "; char arr2[20] = "world!"; char *ret = my_strncpy(arr1, arr2, 1); printf("%s", ret); system("pause"); return 0; }650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/76/5D/wKioL1ZRghbCEDXtAABXKHxx3hM442.png" title="E78`5DJNM8~U_@ARTTU2Y)B.png " alt="wKioL1ZRghbCEDXtAABXKHxx3hM442.png" />
相关文章推荐
- 【C语言】【笔试题】模拟实现memset
- 【C语言】【笔试题】模拟实现memcmp
- 【C语言】【指针相关知识小结】
- 【C语言】【笔试题】使用回调函数编写冒泡排序,可以排序整形数组,也可以排序字符串
- 【C语言】【面试题】C++中String类浅拷贝,深拷贝的传统写法与现代写法
- 【C语言】【笔试题】编写函数: unsigned int reverse_bit(unsigned int value); 翻转二进制序列
- 【C语言】不使用(a+b)/2这种方式,求两个数的平均值。
- 【C语言】【笔试题】找出一组数据中成单出现的数字,其他所有数字都是成对出现的。(移位)
- 【C语言】【笔试题】实现一个函数int my_atoi(char s[]),可以将一个字符串转换为对应的整数。
- 【C语言】【笔试题】实现一个函数int my_atoi(char s[]),可以将一个字符串转换为对应的整数。
- 【C语言】【笔试题】实现函数itoa(int n,char s[]),将整数n这个数字转换为对应的字符串,保存到s中
- 【C语言】【笔试题】编写一个函数itob(int n,char s[], int b),将整数n转换为以b进制的数。保存到s中。
- 【C语言】编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。
- 【C语言】【面试题】5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果问题
- 【C语言】【面试题】5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果问题
- 【C语言】【面试题】【笔试题】使用有限空间,不使用库函数,逆置“student a am i”
- 【C语言】【面试题】【笔试题】使用有限空间,不使用库函数,逆置“student a am i”
- 【C语言】【笔试题】C语言main函数参数含义
- 【C语言】【面试题】【笔试题】对于宏的使用,if endif #define _DEBUG_ ifdef _DEBUG_
- 【C语言】【面试题】【笔试题】对于宏的使用,if endif #define _DEBUG_ ifdef _DEBUG_