c语言 strcpy

来源:百度知道 编辑:UC知道 时间:2024/06/08 23:44:18
struct list
{char name[5];}list;
void performance(char a)
{strcpy(list.name,a);printf("%c",list。name[5]);}
main()
{char a;
perform(a);
}
如何把主函数中的字符a 通过调用函数perform 使得list.name 是a
如何修改 帮我写个正确的完整的 谢谢

首先,a是字符,name是字符串,二者不匹配。
1.a也为字符串。那么可以这么写
#include<string.h>
struct list
{
char name[5];
}list;
void perform(char a[3])
{
strcpy(list.name,a);
printf("%s",list.name);
}
main()
{
char a[]="cba";
perform(a);
}
2.name是字符的话,可以这么写
#include<string.h>
struct list
{
char name;
}list;
void perform(char a[3])
{
list.name=a;
printf("%c",list.name);
}
main()
{
char a='c';
perform(a);
}

#include<iostream>
#include<string>
using namespace std;
struct list
{char name[5];}list;
void performance(char *a)
{strcpy(list.name,a);//printf("%c",list.name);
cout<<list.name<<endl;
}
void main()
{char *a="112";
performance(a);
}

#include<stdio.h>
#include<string.h&