我正在尝试通过链表搜索星号,但是每次我尝试使用 while 循环将头指针与星号进行比较时,程序将无法编译,说它无法将指针与整数进行比较
它在打印列表功能中: while( pt != '*')
/*
*Description: Construction of a social network
*/
#include < stdio.h>
#include < strings.h>
#include < stdlib.h>
#define SIZE 30
#define PEOPLE_SIZE 20
#define PRINT_NETWORK 1
struct people
{
char name[SIZE];
int age;
char gender[SIZE];
int idnumber;
struct friendlist *friends;
};
typedef struct friendlist
{
int friendsname[PEOPLE_SIZE];
struct friendlist *next;
struct people *person;
}node_t;
void scan_friends(FILE *input2, node_t *pt)
{
char *friend_name;
fscanf(input2,"%s", &pt->friendsname);
}
void print_friends(node_t pt)
{
printf("%s ", pt.friendsname);
}
void print_list(node_t *pt)
{
int friendsname[PEOPLE_SIZE];
struct friendlist *next;
struct people *person;
}node_t;
void print_friends(node_t pt)
{
printf("%s ", pt.friendsname);
}
void print_list (node_t *pt)
{
if (pt==NULL)
printf("The list is empty\n");
else
{ // traversing the list
while (pt!=NULL)
{
while (pt != '*')
{
print_friends(*pt);
pt=pt->next;
}
}
}
}
int main(void)
{
int choice=0;
FILE *input; //pointer to people.dat
FILE *input_friends;
int i=0;
struct people people[SIZE];
struct friendlist friendlist[PEOPLE_SIZE];
node_t *headp, *temp, *current=NULL;
char user_name[SIZE];
int user;
input_friends=fopen("friends.dat", "r"); //opens friends file
while(!feof(input_friends))
{
// create a new list element
temp = (node_t *)malloc(sizeof(node_t)); // memory
scan_friends(input_friends, temp); // initialization of element
temp->next=NULL; // setting pointer to null.
if (current==NULL)
{
headp=temp; // setting the head of the list
}
else
{
current->next=temp; // else connecting to previous
}
current=temp; // updating the current element
i++; // count number of elements added
}
fclose(input_friends);
print_list(headp);
}
printf("\n");
return(0);
}