thanks a bunch for your help. I have one more problem though
when adding an additional criminal, when I write to file I have an endless loop somewhere, if it is apparent somewhere in this code, I would appreciate your help, if not I understand
by the way z is initialized to -1
z is being passed to view as num
and (z+1) is being passed to add as num
Code:
void Add(FBI *criminal,int num)//changed counter to num
{
if (num >= 1000)
{
printf("Sorry, you have reached the maximum capacity of entries\n");
}
else
{
printf("\nPlease enter the first name of the criminal you wish to add:");
fflush(stdin);
scanf("%s",criminal[num].fname);
printf("\nPlease enter the last name of the criminal you wish to add:");
fflush(stdin);
scanf("%s",criminal[num].lname);
printf("\nNow enter the Social Security number:");
fflush(stdin);
scanf("%s",criminal[num].SSN);
printf("\nNow enter the criminal's hair color:");
fflush(stdin);
scanf("%s",criminal[num].hair);
printf("\nNow enter the criminal's eye color:");
fflush(stdin);
scanf("%s",criminal[num].eyes);
printf("\nNow enter the criminal's city:");
fflush(stdin);
scanf("%s",criminal[num].city);
printf("\nNow enter the criminal's state:");
fflush(stdin);
scanf("%s",criminal[num].state);
printf("\nNow enter the last ten crimes committed by the criminal:");
printf("\nHit enter after each crime");
printf("\nType q when done. ");
for (x = 0; x < 10; x++)
{
fflush(stdin);
scanf("%s",criminal[num].crimes[x]);
criminal[num].amount = x+1;
if (criminal[num].crimes[x][0] == 'q')
{
criminal[num].amount = x;
criminal[num].crimes[x][0] = '\0';
x = 10;
}
printf(" ");
}
printf("\nNow enter the criminal's ranking (three digits: 001 -for number 1) among the FBI's most wanted list:");
fflush(stdin);
scanf("%s",criminal[num].ranking);
system("cls");
}/*end else*/
}/*end ADD*/
Code:
//writes to file//
wrfile = fopen("FBI.txt","w");
if(wrfile == NULL)
{
printf("\nfile could not be opened");
}
else
{
for (x = 0; x < counter; x++)
{
printf("\nx = %d, counter = %d",x, counter);
fprintf(wrfile,"%s,%s,%s,%s,%s,%s,%s,",criminal[x].fname, criminal[x].lname, criminal[x].SSN,
criminal[x].hair, criminal[x].eyes, criminal[x].city, criminal[x].state);
count10 = 0;
for (y = 0; y < (criminal[x].amount-1); y++)
{
fprintf(wrfile,"%s,",criminal[x].crimes[y]);
count10++;
}
fprintf(wrfile,"%s",criminal[x].crimes[y]);
for (b = 0; b <= (10 - criminal[x].amount); b++)
{
fprintf(wrfile," ,");
}
fprintf(wrfile,"%s ",criminal[x].ranking);
fprintf(wrfile,"\n");
}//end for//
}//end else//
fclose(wrfile);