如何修复警告?
警告:从不兼容的指针类型'char *'分配给'struct people *'</p>
格式“%s”需要“char ”类型的参数,但参数 3 的类型为“char ( )[100]
/* loading user information from the file*/
void load_file(struct people *head)
{
FILE *pFile;
char line[N];
char temp_name[100];
char temp_username[100];
char temp_birthPlace[100];
char new_people[100];
char temp_the_date_of_birth[100];
//open the FILE
if (pFile = fopen("facebook", "r"))
{
// reading the contents of the file line by line
while (fgets(line, N, pFile) != NULL)
{
struct people *new_people = (struct people *)malloc(sizeof(struct people));
//Temporarily saving variables read from file
sscanf(line, "%s,%s,%s,%s",&temp_name,&temp_username,&temp_the_date_of_birth,&temp_birthPlace);
strcpy(new_people->name, temp_name) == 0;
strcpy(new_people->username, temp_username) == 0;
strcpy(new_people->the_date_of_birth, temp_the_date_of_birth) == 0;
strcpy( new_people->birthPlace, temp_birthPlace) == 0;
// adding new people and then putting them as head at the beginning of the linked list
new_people->next = head;
head = new_people;
}
fclose(pFile);
printf("file exists");
}
else
{
printf("file does not exist");
}
return;
}
//sort out users and list up their personal information along with the date of birth and birthplace
void invite_group(struct people *head)
{
FILE *pFile;
char temp_username[100];
char temp_birthplace[100];
char temp_the_date_of_birth[100];
struct people *ptr;
struct people *temp_head = malloc(sizeof(temp_head));
*temp_head = *ptr;
This ArrayList also allows users to add and sort items in the list.
struct people *ListArray[100];
int count = 0;
printf("please input username who invites you\n");
scanf("%s", ptr->username);
while ((ptr->next) != NULL)
{
if(temp_username == ptr->username)
{
pFile = fopen("test.txt", "r");
}
if (pFile != NULL)
{
//input username, the date of birth and birthplace into the file
fprintf(pFile, "username %s,the_date_of_birth %s,birthPlace %s", ptr->username, ptr->the_date_of_birth, ptr->birthPlace);
// list and display username, the date of birth and birthplace
ListArray[count++] = ("%s", "%s", "%s", ptr->username,ptr->the_date_of_birth, ptr->birthPlace);
}
ptr = ptr->next;
}
return;
}