69,382
社区成员
发帖
与我相关
我的任务
分享
char *strncpy(char *s, char *ct, int n);
char *strncat(char *s, char *ct, int n);
int strncmp(char *cs, char *ct, int n);
char *strncpy(char *s, char *ct, int n) {
char *sign = s;
while(n-- > 0)
if(*s++ = *ct) ct++;
return sign;
}
char *strncat(char *s, char *ct, int n) {
char *sign = s;
while(*s)
s++;
while(n-- && (*s++ = *ct++))
;
return sign;
}
#include<stdio.h>
#include "strncpy.c"
int getchar(void);
int main() {
int i;
char c[12] = "ca3456";
char s[4] = "zsev";
//char *z = c;
strncat(c, s, 4);
//if(*(s+3) == 'v')
//printf("%c\n", *(s+4));
for(i = 0; i < 12; i++)
printf("%c\t\n", *(c+i));
return 0;
}
char *strncpy(char *s, char *ct, int n) {
char *sign = s;
while(n-- > 0)
if(*s++ = *ct) ct++;
return sign;
}
int main() {
char s[4] = "zsev";
if(s[4] == '\0')
printf("%s\n", "asd");
else
printf("%s\n","222");
return 0;
}