更新了文件名。开始了数据结构

This commit is contained in:
lzy
2024-04-14 06:55:53 +08:00
parent 9bc7edbf47
commit 45bcb90c6d
69 changed files with 455 additions and 0 deletions

40
Chapter07/chararr.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
char *mystrcpy(char *dest, const char *src)
{
char *ret = dest;
if (NULL != dest && NULL != src)
while ((*dest++ = *src++) != '\0')
;
return ret;
}
char *mystrncpy(char *dest, const char *src, size_t n)
{
int i;
for (i = 0; i < n && (dest[i] = src[i]); i++)
;
for (; i < n; i++)
dest[i] = '\0';
return dest;
}
int main()
{
char str1[] = "helloworld";
char str2[128];
// mystrcpy(str2, str1);
mystrncpy(str2, str1, 5);
puts(str2);
exit(0);
}