帮我看看用C语言该怎么做

来源:百度知道 编辑:UC知道 时间:2024/06/21 08:16:19
将字符数组 a的内容复制到数组字符 b。要求在主函数里完成从键盘上输入一串字符到字符数组 a里,调用自定义函数完成复制,函数的参数用指针。

#include <stdio.h>
int Strcpy(char *a,char *b)
{
int i=0;
while((a[i]=getchar())!='\n')
{
b[i]=a[i];
i++;
}
return i;
}
void main()
{
char a[80],b[80];
int n;
printf("Please input a[] here:\n");
n=Strcpy(a,b);

printf("The result is:\n");
for(int i=0;i<n;i++)
{
printf("%c",b[i]);
}
printf("\n");
}

#include<string.h>
#include<stdio.h>
void copy(char *a,char *b);

main()
{
char a[51],b[51];
printf("input a string,less than 50 words:\n");
gets(a);
copy(a,b);
printf ("oringal %s\n",a);
puts("\n");
printf ("%s\n",b);
getch();
}

void copy(char *a,char *b)
{
stpcpy(b,a);
}