作业:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// 1. 实现字符串连接
// char *my_strcat(char *dest, char *src)
char *my_strcat(char *dest, char *src){
char *s1 = dest;
char *s2 = src;
while(*s1){
s1++;
}
while(*s2){
*s1 = *s2;
s1++;
s2++;
}
*s1 = *s2;
return dest;
}
// 2. 实现字符串拷贝
// char *my_strcpy(char *dest, char *src)
char *my_strcpy(char *dest, char *src){
char *s1 = dest;
char *s2 = src;
while(*s2){
*s1 = *s2;
s1++;
s2++;
}
*s1 = *s2;
return dest;
}
// 3. 实现杨辉三角
// void YangHui(int n, int (*p)[n])
void YangHui(int n, int (*p)[n]){
for(int i = 0; i < n; i++){
for(int k = n-i; k > 0; k--){
printf(" ");
}
for(int j = 0; j <= i; j++){
if(j == 0 || j == i){
*(*(p+i)+j) = 1;
} else {
*(*(p+i)+j) = *(*(p+i-1)+j-1) + *(*(p+i-1)+j);
}
printf("%d ", *(*(p+i)+j));
}
printf("\n");
}
}
int main(int argc, const char *argv[]){
{
printf("====================\n");
char str1[20] = "";
char str2[20] = "";
printf("Please input str1 : ");
gets(str1);
printf("Please input str2 : ");
gets(str2);
printf("str after cat : %s\n", my_strcat(str1, str2));
}
{
printf("====================\n");
char str1[20] = "";
char str2[20] = "";
printf("Please input str1 : ");
gets(str1);
printf("Please input str2 : ");
gets(str2);
printf("str after cat : %s\n", my_strcpy(str1, str2));
}
{
printf("====================\n");
int line = 0;
printf("Please set your line : ");
scanf("%d", &line);
int arr[line][line];
YangHui(line, arr);
}
return 0;
}