i just started this code. this code will be read records from text file and put to the linked list. search/delete/update a contact by first name, last name and city. there are also other functions like insert.
at the first, i want try read one person's contacts, put to the list and print it.
my text file like:
first name
last name
date of born
mail
phone
adres
city
my code:
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
char fname[50];
char lname[50];
int born;
char mail[20];
int phone;
char address[50];
char city[10];
int zip;
struct node* fnnext;
struct node* lnnext;
struct node* citynext;
}NODE;
void print(NODE* head)
{
int y;
NODE* tmp;
tmp=head;
tmp=(NODE*)malloc(sizeof(NODE));
tmp->fnnext=NULL;
tmp->lnnext=NULL;
tmp->citynext=NULL;
while(tmp!=NULL)
{
printf("%s", tmp->fname);
printf("%s", tmp->lname);
printf("%d", tmp->born);
printf("%s", tmp->mail);
printf("%d", tmp->phone);
printf("%s", tmp->address);
printf("%s", tmp->city);
printf("%d", tmp->zip);
tmp=tmp->fnnext;
tmp=tmp->lnnext;
tmp=tmp->citynext;
}
return 0;
}
int main(void) {
NODE* head;
head=(NODE*)malloc(sizeof(NODE));
head->fnnext=NULL;
head->lnnext=NULL;
head->citynext=NULL;
int m=0;
int a;
char c;
FILE *fp;
fp=fopen("text.txt", "r+");
while(!feof(fp))
{
NODE* tmp;
tmp=head;
tmp=(NODE*)malloc(sizeof(NODE));
tmp->fnnext=NULL;
tmp->lnnext=NULL;
tmp->citynext=NULL;
fgets (tmp->fname , 50 , fp);
fgets (tmp->lname , 50 , fp);
fgets (tmp->born , 10 , fp);
fgets (tmp->mail , 20 , fp);
fgets (tmp->phone , 10 , fp);
fgets (tmp->address , 50 , fp);
fgets (tmp->city , 10 , fp);
fgets (tmp->zip , 10 , fp);
}
return 0;
}