I am trying to write a program that generates number plates and assigns them to customers. It successfully generates the number plates and are free to be assigned to customers, but during the assigning the program closes abnormally and can't assign in dev c? here is the code so please help me.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
FILE *fp;
int a,b,c,d,e,f,g,h,i=0;
int q,p,r,s,x,y,z;
long int n,sk,wrt,totalcmbs=0;
char chr[]="UA"; char free[]="Free"; char space[]=" ";
char ch[1];
char *name,*combn,*rd1,*rd2,*rd3;
n=0; q=1;
x=65; y=0; z=65;
printf("We are generating a pattern of order of this type - UAA 000A \n");
printf("The pattern has already been chosen in the code as a license number with 3 number and 1 space as defaults \n");
pattern:
printf("choose an option below: \n");
printf("1. Numbers 0 to 9 \n");
printf("2. Spaces \n");
printf("3. Words - to assign names to license numbers choose this option if the file already exists \n");
scanf("%d",&a);
if(a==1)
{
printf("How many numbers after the first 3 letters? - 3 is preferred by default \n");
scanf("%d",&c);
if(d==1)
{
goto generate;
}
goto pattern;
}
else if(a==2)
{
printf("How many Spaces between the first 3 letters and the remaining letter-number combination?- 1 is deafault \n");
scanf("%d",&d);
if(c==3)
{
goto generate;
}
goto pattern;
}
else
{
goto assign;
}
generate:
fp=fopen("file.txt","a+"); goto C;
A:
if(z<=90)
{
fprintf(fp,"%c Free \n",z); }
z++;
if(z>90)
{
goto B;
}
goto C;
B:
if(z>90)
{
y++;
if(y>999)
{
goto C;
}
z=65;
goto C;
}
if(y<=999)
{
fprintf(fp,"%03d",y);
}
goto A;
C:
if(x>90)
{
fclose(fp);
goto D;
}
if(y!=1000 && z!=91)
{
fprintf(fp,"%s%c",chr,x);
for(g=1;g<=d;g++)
{
fputs(" ",fp);
}
}
if(y>999 && z>90)
{
x++;
y=0;
z=65;
goto C;
}
goto B;
D:
printf("Choose whether to assign names to numbers or not \n");
printf("1. yes \n");
printf("2. no and exit \n");
scanf("%d",&h);
if(h==1)
{
goto assign;
}
printf("press any key to exit \n");
getch();
exit(0);
<big>
assign:
fp=fopen("file.txt","r+");
while(fgetc(fp)!=EOF)
{
if(ch=="F")
{
p=n; }
if(ch=="\n")
{
n++; rewind(fp);
break;
}
n++;
}
rewind(fp);
while(fgetc(fp)!=EOF)
{
if(ch=="\n")
{
totalcmbs++; }
}
Data:
printf("Type the name of the indivivual to assign a license number \n");
scanf("%s",&name);
printf("Type the corresponding valid license number to be assigned e.g UAA 000A with one space between \n");
scanf("%s",&combn);
while(i<=totalcmbs)
{
if(q==1) {
sk=1; }
else
{
sk=(n*q)+1; }
fseek(fp,sk,SEEK_SET);
fscanf(fp,"%s%s%s",rd1,rd2,rd3);
strcat(rd1,space); strcat(rd1,rd2);
if(strcmp(rd1,combn)==0)
{
if(strcmp(rd3,free)==0) {
rewind(fp);
wrt=(n*q)-(n-p); fseek(fp,wrt,SEEK_SET);
fprintf(fp,"%s",name); fflush(stdin);
printf("Do you want to enter more names? \n");
printf("1. yes \n");
printf("2. no \n");
scanf("%d",&s);
if(s==1)
{
goto Data; }
break;
}
else
{
printf("The license number you entered is not free \n");
printf("Do you want to enter another license number? \n");
printf("1. yes\n");
printf("2. no and exit\n");
scanf("%d",&s);
if(s==1)
{
goto Data;
}
else
{
exit(0); }
}
}
q++; if(q>=totalcmbs)
{
printf("The license number you entered is invalid \n");
break;
}
i++;
}
fclose(fp);
printf("press any key to exit \n");
getch();</big>
}