View Single Post
Light Poster
31Dec2011,23:21  
silviatodorof's Avatar
This is the code:
Code:
/**********************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 100

void print_menu(int n);

void main()
{
    int c, a[MAX],temp[MAX],reg,top = 0;
    char carname[80];
    FILE *fp;            
                                            
    print_menu(1);

    scanf_s("%d", &c);
    while (c != 2)
    {
        if (c == 1)
        {
            // Scan in registration
            printf("Please enter Taxi Registration Number\n");
            scanf("%d", &reg);
            a[top] = reg;
            top++;

if((fp = fopen("Taxi Information.txt", "w"))==NULL) {               
printf("Cannot open file.\n");                                      
exit(1);                                                     
}
do {
   printf ("Please enter the car name (CR to quit):\n");
   fflush (stdout);
   /* get the car name */
   gets(carname);
   strcat (carname, "\n");
   fputs (carname, fp);
} while (*carname != '\n');    

fclose(fp);
// Call print_menu
print_menu(1);
scanf("%d", &c);
        }
        else if (c == 2) 
        {
            //remove from front
            int b;
    
            for(b = 0; b <= top; b++)
            {
                temp[b] = a[b+1];
            }

            for (b = 0; b <= top; b++)
            {
                a[b] = temp[b];
            }

            top--;
            printf("Taxi has left\n");
            //print menu
            print_menu(1);
            scanf("%d", &c);
        }
    }
}
// Print menu
void print_menu(int n)
{
    printf(" 1. Arrive \n");
    printf(" 2. Leave  \n");    
}
/**********************************/
The problem is:
After choosing "1", it does not stop at "Please enter the car name (CR to quit)".

Thanks

Last edited by shabbir; 31Dec2011 at 23:48.. Reason: Code blocks