The dreaded seg fault :'(
I am getting a seg fault and have no idea why. I pared my code down and I know the problem is somewhere within this block. I'm wondering if it's because of my declarations. Am I doing bad things with memory?
I'll be working with a linked list of structures called "shipment"s. A structure called tempdata will hold data until it's manipulated.
I'll be working with a linked list of structures called "shipment"s. A structure called tempdata will hold data until it's manipulated.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
typedef struct /*will only be making one tempdata structure*/
{
int number;
char person[30];
char city1[30];
char city2[30];
}tempdata;
typedef struct nodetag
{
int truck;
char owner[30];
char departcity[30];
char arrivecity[30];
int begintime;
struct nodetag *next;
}shipment;
int main(int argc, char *argv[])
{
/*Declarations of Variables*/
shipment *head; /*make ptr to a shipment structure*/
tempdata tempship; /*make new structure*/
FILE *inputfile;
char action;
char endline; /*junk*/
head=NULL; /*to be used later*/
/*Make sure of correct # of parameters. If
incorrect, print error msg.*/
if(argc != 2)
{
printf("Wrong # of parameters!\n");
printf("Usage: %s <input-file-name>\n", argv[0]);
exit(-1);
}
/*Make sure file DOES open. If not, print error msg.*/
if((inputfile = fopen(argv[1], "r"))==NULL)
{
printf("Unable to open file %s for input\n", argv[1]);
exit(-1);
}
while(fscanf(inputfile, "%c %d %s %s %s \n",
&action,
tempship.number,
tempship.person,
tempship.city1,
tempship.city2,
&endline) != EOF)
{
/*then goes into switch statement
which is DEFINITELY not the source of the problem*/
}
fclose(inputfile);
return(0);
}
