Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
typedef struct
{
int year;
int month;
int day;
}date;
typedef struct
{
double latitude;
double longitude;
}location;
typedef struct incList
{
char area[100];
date reported;
int total_missing;
int dead_women;
int dead_men;
int dead_kids;
char cause_of_death[150];
char location_description[500];
location coordinates;
char URL[100];
struct incList *next;
}incident;
int main(int argc,char *argv[])
{
int enter,number_of_incidents;
char end[5],token[]=";",buff[BUFSIZ],incident[2500];
incident *event;
do
{
do
{
printf("Give the number of the source from where you want the program to get the data:\n\n1. From the file\n2. From the keyboard\n");
scanf("%d",&enter);
}
while((enter!=1)&&(enter!=2));
do
{
printf("How many incidents do you want to add to the list?\n");
scanf("%d",&number_of_incidents);
}
while(number_of_incidents<=1);
strcpy(buff,argv);
while (fgets(buff,BUFSIZ,in))
{
event=(incident * )malloc(number_of_incidents*sizeof(incident));
char *token = strtok(buff,";");
strcpy(event->area, token );
token=strtok(NULL,";");
sscanf(token,"%d/%d/%d",&event->reported->day, &event->reported->month, &event->reported->year);
token=strtok(NULL,";");
event->total_missing=strtol(token,NULL,0);
token=strtok(NULL,";");
event->dead_women=strtol(token,NULL,0);
token=strtok(NULL,";");
event->dead_men= strtol(token,NULL,0);
token=strtok(NULL,";");
event->dead_kids=strtol(token,NULL,0);
token=strtok(NULL,";");
strcpy(event->cause_of_death,token);
token=strtok(NULL,";");
strcpy(event->location_description,token);
token=strtok(NULL,";");
sscanf(token,"%.12d",&event->location->latitute);
token=strtok(NULL,";");
sscanf(token,"%.12d",&event->location->longitude);
token=strtok(NULL,";");
strcpy(event->URL,token);
token=strtok(NULL,";");
free(event);
}
printf("Do you want to continue adding or exit?[yes/exit]\n");
scanf("%s",end);
}
while(strcmp(end,"exit")!=0);
return 0;
}
Thanks in advance.