【C语言】【面试题】【笔试题】模拟实现strncpy

#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;
}

时间: 2024-08-11 03:27:30

【C语言】【面试题】【笔试题】模拟实现strncpy的相关文章

老男孩教育-linux面试题-笔试题-1

2. 笔试题-1 2.1 新建一个用户user,密码是123456,并将其加到root组 useradd user -G root && echo "123456"|passwd --stdin user 2.2 显示当前系统的日期和时间 [[email protected] /]# date +%F 2016-08-25 [[email protected] /]# date +%X 10时16分25秒 [[email protected] /]# date +%H:

【C语言】【笔试题】模拟实现strncat

#include <stdio.h> #include <stdlib.h> #include  <assert.h> char *my_strncat(char *dest, const char *src, int len) {     char *ret = dest;     while (*dest)     {         dest++;     }     while (len--)     {         *dest = *src;       

【C语言】【笔试题】模拟实现memset

#include <stdio.h> #include <stdlib.h> #include <assert.h> void my_memset(void *str, char n, size_t count) {     char *dest = (char *)str;     size_t i = 0;     for (i = 0; i < count; i++)     {         *(dest + i) = n;     } } int ma

【C语言】【笔试题】【面试题】实现一个函数,可以左旋字符串中的k个字符

#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include <string.h> void reserve(char *left,char*right) { while (left < right) { char tmp = *left;     *left = *right; *right = tmp; left++; right--; } } int main() { char arr[10] = "

【C语言】【笔试题】【面试题】判断一个字符串是否为另外一个字符串旋转之后的字符串

#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include <string.h> void reserve(char *left, char*right) { while (left < right) { char tmp = *left; *left = *right; *right = tmp; left++; right--; } } void left_reserve(char arr[], int k)

【C语言】【笔试题】C语言main函数参数含义

#include <stdio.h> int main(int argc, char *argv[],char *envp[])//第一个参数argc只的是变量的个数,第二个参数值得是对应变量的位置,第三个指的是main函数中的所有环境变量 { int i = 0; for (i = 0; envp[i] != NULL; i++) { printf("%s\n", envp[i]); } if (strcmp(argv[1], "-a") == 0)

【C语言】【笔试题】实现一个函数int my_atoi(char s[]),可以将一个字符串转换为对应的整数。

#include <stdio.h> int  my_atoi(char s[5]) { int flag= 1;//在这作为判断'-'的开关 int ret=0; char *p=s; if (*p=='-')//如果第一个字符为'-',那么flag开关就会打开,置成-1: { flag=-1; } if (*p == '+'||*p=='-')//如果第一个字符为'-'或者为'+',那么不再做处理,直接跳到第二个字符 { p++; } while(*p!='\0') { if((*p>

【C语言】【笔试题】实现函数itoa(int n,char s[]),将整数n这个数字转换为对应的字符串,保存到s中

#include <stdio.h> static int i=0;//定义全局变量i 作为数组s[]的下标 int itoa(int n,char s[]) {  if(n<10) { s[i]=n+'0'; } else  { itoa(n/10,s);//递归 i++; n=n%10;//最后一位的数字 s[i]=n+'0'; } s[i+1]='\0';//字符串结束标志 } int main() { char s[6]; int num=0; printf("inpu

【C语言】【笔试题】编写一个函数itob(int n,char s[], int b),将整数n转换为以b进制的数。保存到s中。

#include <stdio.h> static int i=0; int itob(int n,char s[],int b) { if(n<2) { s[i]=n+'0'; } else { itob(n/2,s,b); //递归 i++; n=n%2; s[i]=n+'0'; } s[i+1]='\0';//结束标志 return 0; } int main () { char s[20]; int num=0; scanf("%d",&num); i

Java面试题笔试题:

选择题(共50题,每题1.5分,共75分.多选题选不全或选错都不得分.)1. 以下属于面向对象的特征的是(C,D).(两项)A) 重载B) 重写C) 封装D) 继承 2. 以下代码运行输出是(C)public class Person{private String name="Person";int age=0;}public class Child extends Person{public String grade;public static void main(String[]