I don't seem to get what's wrong..
When i try to test what comes out of choice and HelpP->id
I'll get choice = a3, but HelpP->id = t <----???
And another thing Can it be done a easier way than this.
I need to take some data of from the file, and spilt the stings
up, so I can use fx the birthday to calculate with.
And later on the should be a sort, som one can search after diff. kinds og sportspeople.
tks hope someone can help me..
my code is:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <stdlib.h>
#define TEXTFILE "person.txt"
int case3(void)
{
FILE *infile;
char choice[4];
int ch, entries;
char personbuffer[1000];
typedef struct person personT;
struct person
{
char id;
char name[40];
int day, month, year;
};
personT *PpersonT, *HelpP;
infile = fopen(TEXTFILE, "r");
printf("Her e is a list from the file:\n\n");
while ((ch=fgetc(infile)) !=EOF)
{
fputc(ch,stdout);
}
printf("\n\n");
printf("How many persons do you want?: ");
scanf("%d", &entries);
fflush(stdin);
/* Allocation */
PpersonT = (personT*)malloc(sizeof(personT));
for (HelpP=PpersonT; HelpP-PpersonT < entries; ++HelpP)
{
printf("Make your choice .\n"
"Ex: [ a3 for Tiger Woods]: ");
scanf("%s", &choice);
fflush(stdin);
if ((infile = fopen(TEXTFILE, "r")) !=NULL)
{
while(fgets(personbuffer,(int)sizeof personbuffer, infile) !=NULL)
{
if(sscanf(personbuffer, "%[^,],%[^,],%d.%d.%d", &HelpP->id,
&HelpP->name,&HelpP->day,
&HelpP->month, &HelpP->year) == 5)
/* printf("Choice: %s\n", choice); TEST */
/* printf("Rec->id: %s\n", HelpP->id); TEST */
if(strcmp(&HelpP->id, choice) == 0)
{
printf("Your Choice:\n");
printf("%s %s %d %d %d", &HelpP->id, &HelpP->name,&HelpP->day,
&HelpP->month, &HelpP->year);
}
else
printf("No luck");
}
}
}
getch();
return 1;
}