Well... this is what I have now, and it's still not working. What am I missing? D:
It says the friend_t head; variable isn't working.
This is completely incomplete so ignore everything except the linked list part.
Code:
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#define SIZE 20
#define SIZE2 100
#define LEN 20
typedef struct friend friend_t;
typedef struct person
{
char *name;
int age;
int id_number;
friend_t* friends;
} person_t;
struct friend
{
person_t *user;
struct friend* next;
};
void print_users(person_t *s)
{
int i;
for(i=0;i<SIZE;i++)
printf("\n%s: Age: %d, ID Number: %d\n",s[i].name,s[i].age,s[i].id_number);
}
void find_user(char *tempc, person_t *t, person_t *arr)
{
int i;
for(i=0;i<SIZE;i++)
{
if(strcmp(tempc, arr[i].name) == 0)
t = arr;
}
}
friend_t *find_friends(person_t *arr, char *separator, FILE* data)
{
friend_t *t1, *h, *p;
person_t *t2;
char *tempc = 0; // used to check for separator
fscanf(data, "%s", tempc);
while(tempc != separator)
{
t1 = (friend_t*)malloc(sizeof(friend_t)); // memory allocation
t2 = (person_t*)malloc(sizeof(person_t)); // " "
find_user(tempc, t2, arr); // ?!
t1->next = NULL;
t1->user = t2;
t1->user->name = tempc;
if(p == NULL)
h = t1;
else
{
p->next = t1;
p = t1;
}
}
return h;
}
int main(void)
{
person_t s[SIZE];
/* Say you array of people is person_t people[20] in your main function. Then people[0]. friend_list is a head pointer to a struct of friend_t.*/
friend_t *head = 0;
char *separator = "~";
int i;
int temp = 1;
int get;
FILE* data = fopen("final_data.dat", "r");
for(i=0;i<SIZE;i++)
fscanf(data, "%s %d %d" ,s[i].name,&s[i].age,&s[i].id_number);
head = find_friends(s, separator, data);
while(temp == 1) {
printf("List of commands: \n\t(1) View users \n\t(2) Add Friend \n\t(3) Delete Friend \n\t(4) Modify Attribute \n\t(5) Sort by attribute \n\t(6) Find degree of separation \n\t(7) Find user with most friends \n\t(8) Find user with least friends \n\t(9) Check to see if a friendship exists \n\t(10) Quit");
printf("\n\nEnter a command: ");
scanf("%d", &get);
switch(get)
{
case 1:
print_users(s);
break;
case 2:
// add_friend();
break;
case 3:
// delete_friend();
break;
case 4:
// change_atr();
break;
case 5:
// sort();
break;
case 6:
// separation();
break;
case 7:
// most_fr();
break;
case 8:
// least_fr();
break;
case 9:
// check_fr();
break;
case 10:
temp = 0;
break;
}
}
printf("\n\n");
return 0;
}