I'm trying to read from a file in C, and feed the data into 5 different fields of a structure using spaces as a delimiter. I have a list of over 70 different patients, each formatted as such,
Mark Cruz 5627 193.0 3.0
Joseph Feminella 4328 194.0 3.5
Eriverto Lopez 7899 195.0 7.9
Austin Duarte 3056 196.0 12.4
Jacob England 1453 197.0 6.7
There aren't new lines between each, they are all on after the other. When I run this program it seems to start about halfway through the file each time, prints a ')' before 'First Name:' every time, and ends with a patient having zeros for every field.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
char pln[30];
char pfn[20];
int pid;
float pwt;
float phgnum;
struct node* next;
struct node* back;
}node;
int main(){
FILE *fp;
char c;
node* newptr;
fp = fopen("info.txt","r");
if(fp == NULL){
printf("ERROR File Doesn't exist\n");
}
while(c != EOF){
newptr = (node*)malloc(sizeof(node));
newptr->back = NULL;
newptr->next = NULL;
newptr->phgnum = 0;
newptr->pid = 0;
newptr->pwt = 0;
fscanf(fp,"%s %s %i %f %f",newptr->pfn,newptr->pln,&newptr->pid,&newptr->pwt,&newptr->phgnum);
c = getc(fp);
printf("First Name: %s\n",newptr->pfn);
printf("Last Name: %s\n",newptr->pln);
printf("PID: %i\n",newptr->pid);
printf("Weight: %f\n",newptr->pwt);
printf("HG1AC: %f\n",newptr->phgnum);
printf("\n\n\n)");
}
}