This code works fine when I search the file for Id no, but when I try to change the while from:
while(index != ARREYSIZE) {
if(strcmp(record[index].id, choice2) == 0)
to:
while(index != ARREYSIZE) {
if(strcmp(record[index].car, choice2) == 0)
And chose i the switch to search for car, that won't work.
Any good ideas how/why this may fail??


code----------------------->

#define FILENAME "datafile.txt"
#define ARREYSIZE 30
int getcostumer(void)
{
char buffer[BUFSIZ];
FILE *output; /* pointer to the datafile */

int index = 0;
int choice;
char choice2[30];

struct indata
{
char id[3];
char name[BUFSIZ];
int age;
char car[20];
}record[30];

/* Try to make a variable input to choose */
printf("You can choose to search for press 1(Id), 2(Name), 3(Age) or 4(Car)\n");
printf("What do you want to search for: ");
scanf("%d", &choice);
fflush(stdin);
switch(choice){
case 1:
printf("please input the Id number: ");
scanf("%s", &choice2);
break;
case 2:
printf("please input the name: ");
scanf("%s", &choice2);
break;
case 3:
printf("please input the age: ");
scanf("%d", &choice2);
break;
case 4:
printf("please input the car name: ");
scanf("%s", &choice2);
break;
default:
printf("Sorry; Record was not found in the database");
break;
}

if ((output = fopen(FILENAME, "r")) !=NULL)
{
for(index=0; ;++index)
while(fgets(buffer,(int)sizeof buffer, output) !=NULL)
{
if(sscanf(buffer, "%[^,],%[^,],%d,%[^,]", &record[index].id,
&record[index].name,
&record[index].age,
&record[index].car) == 4)

while(index != ARREYSIZE) {
if(strcmp(record[index].id, choice2) == 0)
{
printf("The selections you made is found.\n");
printf("Id : %-25s\n", record[index].id);
printf("Name: %-25s\n", record[index].name);
printf("Age : %-25d\n", record[index].age);
printf("Car : %-25s\n", record[index].car);
getch();
return 1;
}
break;
}

}
}
return 0;
}


int main(void)
{
getcostumer();

getchar();
return 0;
}
-Datafile.txt...................
a1, Morten Jasper, 28, Volvo
a2, Sara Klum, 22, Datsun
a3, Mikkel jensen, 32, Fiat
b1, Kenneth Mikkelsen, 41, Volvo
b2, Hans Niel, 33, Fiat
b3, Kasper Hansen, 62, Ford
c1, Josh Narret, 21, Ford
c2, Dave Kunnet, 24, Porsche