以下のような関数に渡す必要のある文字列があります。
scanf("%s%d",&name,&telno);
addatend(telno,name);
どこ
char name[MAX];
次の警告が表示されます:
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[50]’ [-Wformat]
もう1つのchar
ポインターとポイントを持つなどの変更を試みましたname
。しかし、警告は残ります。
関数で私はstrcpyを持っています
strcpy(addnode->name,name1);
これは、構造内のname
frommain
からinに対処しています。しかし、このラインにはセグメンテーション違反があります。name
addnode
スプリント(この行では問題はありませんでした)とvalgrindをチェックインしようとしましたが、間違いを特定できませんでした。したがって、助けを求めてここに来ました。前もって感謝します..
コード:
typedef struct Mystruct{
char *name;
int telno;
struct Mystruct *nextp;
}data;
void addatend(int telno1, char* name1)
{
data *addnode, *previousnode;
addnode = malloc (sizeof(data));
if(addnode == NULL)
{
printf("Memory allocation failed...Exiting");
exit(0);
}
strcpy(addnode->name,name1); //error Part of the code.