Thread: Checking array for string

  1. #31
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    I really appreciate all the suggestions, but I'm not any less confused now. The example program given uses char*, but before we were talking about using const char [][].

    Maybe it helps if I just give the whole code of my test program. It does compile now and It doesn't crash either. Unfortunatly however, it doesn't do what I want it to do. It just uses "result" as whatever value I gave it at the declaration.
    This is what I have now:
    The function:
    Code:
    int stringcheck(const char* string1_to_check_for,const char* string2_to_check_for,const char array_to_check[][8],int length_of_array){
    
    int i=0;
    int result=0;
    
    for(i = 0; i < length_of_array; i++)
    {
        if (strcmp(string1_to_check_for, array_to_check[i]) == 0 ||
            strcmp(string2_to_check_for, array_to_check[i]) == 0)
        {
            return result = 1;
            break;
        }
    }   
    
    return result = 0;
    }
    And in the main for testing this function:
    Code:
    const char comb_array[][8] = 
    {    "13",
         "26",
         "158",
         "86",
         "88",
         "1212",
         "142",
         "89",
         "14",
         "410",
         "1116",
         "168",
         "12",
         "34"
    };    
        
        
    
    
    int result=5;
    int startype1 = 1;
    int startype2 = 4;
    int comb_array_pointer = 14;
    char current_comb1[8];
    char current_comb2[8];
    
        
    sprintf(current_comb1, "%d%d",startype1,startype2);
    sprintf(current_comb2, "%d%d",startype2,startype1);
    
    printf("checking for the strings: '%s' '%s' \n", current_comb1, current_comb2);
    
    stringcheck(current_comb1,current_comb2,comb_array,comb_array_pointer);   
    
    printf("String found true/false (1/0): %d\n",result);
    Maybe you can help me, using what I have so far?
    Nothing to see here, move along...

  2. #32
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    shoouldn't you assign to result something to see the changes in this variable?
    currently you just ignore the return value of your checking function
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #33
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    Why does it ignore the return value? First i define "result" as whatever and then I run the function and I thought it would use the new changed version of "result".
    Nothing to see here, move along...

  4. #34
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    Oh wait! I must use result = stringcheck(arguments);
    But in that case, why would i want to return "result" from my function, if i can't even use this variable??
    Nothing to see here, move along...

  5. #35
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, let's see now, in my example, a[][] is a 2D char array
    your array_to_check[][] is also a 2D char array.

    I needed the "address of" operator highlighted in red, below, in my example program.

    You need it, but still have not added it.

    Wake up!


    Code:
    if((strcmp(string, &a[i])) == 0)
    
    if (strcmp(string1_to_check_for, array_to_check[i]) == 0 ||
            strcmp(string2_to_check_for, array_to_check[i]) == 0)

  6. #36
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Adak View Post
    You need it, but still have not added it.
    and what for he needs it?

    array_to_check[i] is char*

    why to modify it to char**? ctrcmp does not know what todo with it
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #37
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm with vart on this one.

    @Ayreon:
    The result inside your "is this a match" is a different variable "result" from the one inside your main function - they just HAPPEN to have the same name, but if you call one of them fred, it will not change anything. Return means "give this back as a value from this function" - think of it as a mathematical function, e.g. sin() or sqrt() - you do use them with a "x = sqrt(y);", right? You do not know what variable names are used inside sqrt() - nor should you. The same applies to your own functions - the names of variables inside one function has nothing to do with names of variables in another function.

    It is something called "scope". The area where a particular variable is available is "its scope", and it is always the pair of braces that enclose the variable that define it's scope.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #38
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    int stringcheck(const char* string1_to_check_for,const char* string2_to_check_for,const char array_to_check[][8],int length_of_array){
    
    int i=0;
    int result=0;
    
    for(i = 0; i < length_of_array; i++)
    {
        if (strcmp(string1_to_check_for, array_to_check[i]) == 0 ||
            strcmp(string2_to_check_for, array_to_check[i]) == 0)
        {
            return result = 1;
            break;
        }
    }   
    
    return result = 0;
    }
    Result, in this function is completely meaningless. You only assign it within the return statement - you should EITHER use two return statements, eg. "return 1", or use a "result = 1" and then a single "return result" at the end of the function (where you initialize result = 0; and set it to one in the loop.

    If you go with the two return statements, you will not need the break statement, as return means "leave this function now". Of course, if you have a single return, then using a break will reduce the amount of loop iterations.

    There are two "styles" when it comes to return statements - one says have only one return statement (at the end of the function), the other is "return wherever and whenever the result is known and the function is 'done'". You should CHOOSE which one you follow (it is obviously still ALLOWED to one single return in the latter style). There are good arguments for both, and I'm not going to explain much about it here - start a new thread if you really want to have a discussion on that subject.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #39
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    The function works now, without the & though.
    Thanks for the explenation on the function about return, I totally get that now.

    When I implement this function in my bigger program though, I get a whole lot of incompatible pointer types, thingies without a cast, assignments to read-only locations and that sort of stuff.
    (Well it starts with one of these but when I try to fix stuff, I only get one of these errors instead.)

    I'll just start another topic on that, it hasn't got much to do with the checking function anymore.
    Nothing to see here, move along...

  10. #40
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by vart View Post
    and what for he needs it?

    array_to_check[i] is char*

    why to modify it to char**? ctrcmp does not know what todo with it
    Of course, you mean strcmp().

    I'm not sure myself, but when I removed the '&' to check it, my example program would no longer run, although it compiled just fine.

  11. #41
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    One more question I think, could still be suitable for this topic:

    What if my array_to_check changes everytime before I run my function. It doesn't change during the running of the function but in the larger program it is not defined as a const char because it is not constant.
    Still I had to make it const in my function argument, so now I get incompatible argument types.
    And if I do define this array to be a constant in the main program, the argument types are fine, but I get an "assignment to read-only location" error.

    What should I do?
    Nothing to see here, move along...

  12. #42
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You have to work around that. For whatever reason, a const parameter does not accept incoming mutable arguments, which doesn't really make sense, but...

    You can avoid a cast with something like
    Code:
    void foo(const char quz[][8]);
    
    int main()
    {
        char test[8][8];
        const char (*arg)[8];
    
        arg = test;
        foo(arg);
        return 0;
    }
    Of course, all of these are bad variable names, but the example is sound.

  13. #43
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to do that since a local pointer is made, which is const, and assigned the address from the array you pass. That's why your original array can be non-const while the one the function accepts can be const. This is basics basically.
    However, why it does not work for you, I can only guess. The best, and easiest, way to figure it out is to show the code, I guess.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    Registered User
    Join Date
    Mar 2009
    Posts
    1
    can anyone please help me.... my program is not working and i can't figure out the mistakes...please a volunteer can help. thanks in advance.


    Code:
    /* 
    
    *------- Module name : Airline.c
    *------- Purpose     : Program For a Small Airline Enterprise
    		       Program will perform basic operation like
    		       booking a seat,issue ticket to passenger.  
    *------- Date created: 28/03/2008
    *------- Coded by    : Doosan Pagooah
    
    */
    
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    
    #define max_size 64
    
    /*************************************************/
    
    /*************************************************/
    
    void  main()
    {
    
        time_t    time_now;
    	FILE *tim,*tim_1;
    	char week_day[3],dd[1],mm[2],yy[3],hour[5],ans;
    	void date_in(),header(),footer(),loader();
    
    	int val,mmm,yyy,function1();
       
        time(&time_now);     /* get time in seconds */
         
        header();
          
    
        tim=fopen("tim.dat","w");
    	fprintf(tim,"%s",asctime(localtime(&time_now)));
        fclose(tim);
        	
    	tim_1=fopen("tim.dat","r");
    	fscanf(tim_1,"%s%s %c%c %s %c%c%c%c",&week_day,&mm,&dd[0],&dd[1],&hour,&yy[0],&yy[1],&yy[2],&yy[3]);
    
    	
    	
    	printf("\n\n\n\n\n\t\t\t       DATE : %c%c %c%c%c %c%c%c%c \n\n\n\n\n\n\n\n\n",dd[0],dd[1],mm[0],mm[1],mm[2],yy[0],yy[1],yy[2],yy[3]);
    	
    	mmm=atoi(dd);
    	yyy=atoi(yy);
    	
    
    	footer();
    
    	printf("\t Do You Agree That The Above Date Is Today's Date <Y/N> ? : ");
        scanf("%c",&ans);
    	
    	ans=toupper(ans);
    
    	if (ans=='Y')
    		val=1;
    	else 
    		val=0;
    
    	switch(val)
    	{
    
    	case 1:
    		system("cls");
    		header();
    		printf("\n\n\t   Taking Into Account That The Displayed Date Below Is Correct,\n\t       The System Will Process Its data With Respect To It.\n\n\n");
    		printf("\n \t\t\t         DATE: %d %s %d \n\n\n\n\n\n",mmm,mm,yyy);
    		footer();
    		loader();
    		function1(mmm,mm,yyy);
    		break;	
    			
    			
    	case 0:	
    		system("cls");
    		header();
    		printf(" \n\n\t    Noting That The Displayed Date Below is Not Today's Date,\n\t      You Will Be Prompt To Input Today's At The Next Menu \n");
    		printf("\n \t\t\t         DATE: %d %s %d \n\n\n\n\n\n",mmm,mm,yyy);
    		footer();
    		loader();
    		date_in();
    		break;
    
    	}
    
    		fcloseall();
        
    
    }
    
    void date_in()
    {
    
    void header(),footer(),loader();
    int mmm,yyy;
    char mm[2];
    
    system("cls");
    header();
    printf("\n\n\n\n   You Are Requested To Input Today's Date <E.g 30 Nov 1987> : ");
    
    scanf("%d %s %d",&mmm,&mm,&yyy);
    function1(mmm,mm,yyy);
    		
    }
    
    
    /*************************************************/
    
    /*************************************************/
    
    
    int function1(long int dayofmonth, char smonth[],long int year)
    
    {
    long int month,r;
    int dayofweek(),isleapyear(),dateadd(),calcul_day(),error=0,day_off=0;
    char ans;
    void display(),compare(),date_in(),main1();
    
    FILE *fp;
    
    fp=fopen("output.dat","w");
    
    
    smonth[0]=toupper((int) smonth[0]);
    smonth[1]=tolower((int) smonth[1]);
    smonth[2]=tolower((int) smonth[2]);
    
    month=0;
    if      (!strcmp(smonth,"Jan")) month=1;
    else if (!strcmp(smonth,"Feb")) month=2;
    else if (!strcmp(smonth,"Mar")) month=3;
    else if (!strcmp(smonth,"Apr")) month=4;
    else if (!strcmp(smonth,"May")) month=5;
    else if (!strcmp(smonth,"Jun")) month=6;
    else if (!strcmp(smonth,"Jul")) month=7;
    else if (!strcmp(smonth,"Aug")) month=8;
    else if (!strcmp(smonth,"Sep")) month=9;
    else if (!strcmp(smonth,"Oct")) month=10;
    else if (!strcmp(smonth,"Nov")) month=11;
    else if (!strcmp(smonth,"Dec")) month=12;
    
    
    if (month==2 && dayofmonth==29 && !isleapyear(year))
    {
    	printf("\n\n\n\n\t\t\t ERROR : %d Is Not A Leap Year \n\n\n",year);
    	error=1;
    }
    
    else
    
    if(month!=1 && month!=2 && month!=3 && month!=4 && month!=5 && month!=6 && month!=7 && month!=8 && month!=9 && month!=10 && month!=11 && month!=12)
    {
    	printf("\n\n\n\n\t\t THERE IS AN ERROR IN THE INPUT OF MONTH ! ! !\n\n\n "); 
    	error=1;
    }
     
    else 
    
    if (month==1 && (dayofmonth<1 || dayofmonth>=30) )
    {
        printf("\n\n\n   Error in input, January can't have date greater that 31  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    if (month==2 && (dayofmonth<1 || dayofmonth>=30) )
    {
        printf("\n\n\n Error in input, February can't have date greater that [28/ 29]  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    
    if (month==3 && (dayofmonth<1 || dayofmonth>31) )
    {
    	printf("\n\n\n   Error in input, March can't have date greater that 31  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else
    
    
    if (month==4 && (dayofmonth<1 || dayofmonth>30) )
    {
    	printf("\n\n\n   Error in input, April can't have date greater that 30  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else
    
    if (month==5 && (dayofmonth<1 || dayofmonth>31) )
    {
        printf("\n\n\n   Error in input, May can't have date greater that 31 or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    if (month==6 && (dayofmonth<1 || dayofmonth>30) )
    {
    	printf("\n\n\n   Error in input, June can't have date greater that 30  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    if (month==7 && (dayofmonth<1 || dayofmonth>31) )
    {
        printf("\n\n\n   Error in input, July can't have date greater that 31 or less that 1  \n\n\n\n" );
    	error=1;
    }
    	else 
    
    if (month==8 && (dayofmonth<1 || dayofmonth>31) )
    {
        printf("\n\n\n   Error in input, August can't have date greater that 31 or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    if (month==9 && (dayofmonth<1 || dayofmonth>30) )
    {
    	printf("\n\n\n   Error in input, September can't have date greater that 30  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    if (month==10 && (dayofmonth<1 || dayofmonth>31) )
    {
        printf("\n\n\n   Error in input, October can't have date greater that 31 or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    if (month==11 && (dayofmonth<1 || dayofmonth>30))
    {
    	printf("\n\n\n   Error in input, November can't have date greater that 30  or less that 1  \n\n\n\n" );
    	error=1;
    }
    else
    
    if (month==12 && (dayofmonth<1 || dayofmonth>31) )
    {
        printf("\n\n\n   Error in input, December can't have date greater that 31 or less that 1  \n\n\n\n" );
    	error=1;
    }
    else 
    
    {
    	system("cls");
    	header();
    	printf("\n\n\t\t     The %2d",dayofmonth);
    if (!(r=dayofmonth%10) || r>3 || dayofmonth/10==1) 
    	printf("th");
    else switch(r)
    {
    case 1:printf("st");
    break;
    case 2:printf("nd");
    break;
    default:printf("rd");
    }
    printf(" Of %s %d Falls On A ",smonth,year);
    switch(dayofweek(dayofmonth,month,year))
    {
    case 0:printf("Monday");
    break;
    case 1:printf("Tuesday");
    break;
    case 2:printf("Wednesday");
    break;
    case 3:printf("Thursday");
    break;
    case 4:printf("Friday");
    break;
    case 5:printf("Saturday \n\n\n\t\t\t     So We Can't Work Today \n\n\n\n");
           day_off=1;
    	   footer();
    break;			   
    default:
    	{
    		printf("Sunday \n\n\n\t\t\t      So We Can't Work Today \n\n\n\n");
    		day_off=1;
    		footer();
    		
    	}
    }
    printf("\n");
    
    }
    
    
    
    if (error==1)
    {
    	footer();
    	printf("\t\t Would You Wish To Re-Enter The Date ? <Y/N> : ");
    	scanf("%s",&ans);
    	ans=tolower(ans);
    	if (ans=='y')
    			date_in();
    	else
    	{
    		printf("GOOD BYE \n");
    	}
    
    }
    
    
    else
    
    if (day_off!=1)
    	{
    		dateadd(dayofmonth,month,year);
    		compare();
    		main1();
    	}
    
    return 0;
    }
    
    /*************************************************/
    
    /*************************************************/
    
    int isleapyear(int year)
    
    {
    	return year%100 ? !(year%4) : !(year%400);
    
    }
    
    
    /*************************************************/
    
    /*************************************************/
    
    int dayofweek(int dayofmonth,int month,int year)
    {
    
    	int a,b,c,day,febdays,t;
    
    febdays=isleapyear(year) ? 29 : 28;
    a=year-2000;
    t=a>0;
    b=(a-t)/4+t;
    c=(a-t)/100;
    c-=c/4;
    day=a+b-c;
    while (--month)
    if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10)
    day+=31;
    else if (month!=2) day+=30;
    else day+=febdays;
    day+=dayofmonth+4;
    day%=7;
    return day>=0 ? day : day+7;
    }
    
    
    
    /*************************************************/
    
    /*************************************************/
    void pass()
    {
    	char pass[3];
    	int chance=0;
    
    	for (chance=3;chance!=0;--chance)
    	
    	{
    		printf("\n ENTER PASSWORD \t");
    		scanf("%s",pass);
    
    		if ( (pass[0]='c') && (pass[1]=='e') && (pass[2]=='r') && (pass[3]='n') )
    		
    		{
    			printf("\n Good password");
    			break;
    		}
    
    		else 
    		
    		if (chance==1) 
    		printf("Good Bye ");
    
    		else		
    		{
    			printf("\n Wrong password");
    			printf("\n Chance[s] left: %d\n",(chance-1));
    			
    			
    		}
    
    	}
    
    }
    
    
    /*************************************************/
    
    /*************************************************/
    
     int dateadd(int day,int month, int year)
     
     {
    	 int calcul_day(),n=0;
    
    	
    	 for (++day;n<5;++day)
    	 {
    	 
    	 if ((calcul_day(day,month,year))==1)
    	 {
    		continue;
    	 }
    	 else
    	 
    	 {
    		++n;
    	 }
    	 
    	 }
    
    	 return 0;
     }
    
    
     /*************************************************/
    
    /*************************************************/
    
    int calcul_day (int day,int month, int year)
     {
    	
    	
    	 
    	 int febdays,resultday();
    
         febdays=isleapyear(year)? 29 : 28;
    
    	 if ( (month==1 || month==3 ||month==5 || month==7 || month==8 || month==10) && (day>31) )
    		{
    		 ++month;
    		 day=day-31;
    		}
    	 else
    		 
    	 if ( (month==4 || month==6 || month==9 || month==11 ) && (day>30) )
    		{
    		 ++month;
    		 day=day-30;
    		}
    	 else
    	 	{
    			
    		}
    	 if (month==2 && day>febdays)
    		{
    		 ++month;
    		 day=day-febdays;
    		}
    
    	 else
    	 
    	 if (month==12 && day>31)
    		 {
    			 month=1;
    			 day=day-31;
    			 ++year;
    		 }
    		 	 	    
    		
    	 if ( ((dayofweek(day,month,year))==5) || ((dayofweek(day,month,year))==6 ) )
    	
    		return 1;
    	
    	else
    	
    		
    	{
    		resultday(day,month,year); 
    	
    
    	}
    
    	return 0;
     }
    	
    
    /*************************************************/
    
    /*************************************************/
    
    int resultday(int day,int month,int year)
    
    {
    
    FILE *fp;
    char smonth[2],n_day[9]={' ',' ',' ',' ',' ',' ',' ',' ',' '};
    int dayofweek();
    
    
    if (month==1)
    {
    smonth[0]='J';
    smonth[1]='a';
    smonth[2]='n';
    }
    else 
    
    if (month==2)
    {
    smonth[0]='F';
    smonth[1]='e';
    smonth[2]='b';
    }
    else 
    
    if (month==3)
    {
    smonth[0]='M';
    smonth[1]='a';
    smonth[2]='r';
    }
    else 
    
    if (month==4)
    {
    smonth[0]='A';
    smonth[1]='p';
    smonth[2]='r';
    }
    else 
    
    if (month==5)
    {
    smonth[0]='M';
    smonth[1]='a';
    smonth[2]='y';
    }
    else 
    
    if (month==6)
    {
    smonth[0]='J';
    smonth[1]='u';
    smonth[2]='n';
    }
    else 
    
    if (month==7)
    {
    smonth[0]='J';
    smonth[1]='u';
    smonth[2]='l';
    }
    else 
    
    if (month==8)
    {
    smonth[0]='A';
    smonth[1]='u';
    smonth[2]='g';
    }
    else 
    
    if (month==9)
    {
    smonth[0]='S';
    smonth[1]='e';
    smonth[2]='p';
    }
    else 
    
    if (month==10)
    {
    smonth[0]='O';
    smonth[1]='c';
    smonth[2]='t';
    }
    else 
    
    if (month==11)
    {
    smonth[0]='N';
    smonth[1]='o';
    smonth[2]='v';
    }
    else 
    
    if (month==12)
    {
    smonth[0]='D';
    smonth[1]='e';
    smonth[2]='c';
    }
    
    
    switch(dayofweek(day,month,year))
    {
    case 0:/*printf("Monday");*/
    	   n_day[0]='M';n_day[1]='o';n_day[2]='n';n_day[3]='d';n_day[4]='a';n_day[5]='y';
    	   break;
    case 1:/*printf("Tuesday");*/
    	   n_day[0]='T';n_day[1]='u';n_day[2]='e';n_day[3]='s';n_day[4]='d';n_day[5]='a';n_day[6]='y';
    	   break;
    case 2:/*printf("Wednesday");*/
    	   n_day[0]='W';n_day[1]='e';n_day[2]='d';n_day[3]='n';n_day[4]='e';n_day[5]='s';n_day[6]='d';n_day[7]='a';n_day[8]='y';
    	   break;
    case 3:/*printf("Thursday");*/
    	   n_day[0]='T';n_day[1]='h';n_day[2]='u';n_day[3]='r';n_day[4]='s';n_day[5]='d';n_day[6]='a';n_day[7]='y';
    	   break;
    case 4:/*printf("Friday");*/
           n_day[0]='F';n_day[1]='r';n_day[2]='i';n_day[3]='d';n_day[4]='a';n_day[5]='y';
    	   break;
    case 5:/*printf("Saturday");*/
    	   n_day[0]='S';n_day[1]='a';n_day[2]='t';n_day[3]='u';n_day[4]='r';n_day[5]='d';n_day[6]='a';n_day[7]='y';
    	
    	break;
    	
    default:
    		/*printf("Sunday");*/
    		n_day[0]='S';n_day[1]='u';n_day[2]='n';n_day[3]='d';n_day[4]='a';n_day[5]='y';
    	
    		break;
    }
    printf("\n");
    
    fp=fopen("output.dat","a+");
    fprintf(fp,"%d %c%c%c %d %c%c%c%c%c%c%c%c%c\n",day,smonth[0],smonth[1],smonth[2],year,n_day[0],n_day[1],n_day[2],n_day[3],n_day[4],n_day[5],n_day[6],n_day[7],n_day[8]);
    fclose(fp);
    return 0;
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void display()
    {
    	FILE *vw;
    	int numring=0,h=16;
    	char day[10],n_day[5],month[10],year[5];
    
    	vw=fopen("output.dat","r");
    
    	fscanf(vw,"%s %s %s %s",&n_day,&month,&year,&day);
    
    	while (!feof(vw))
    	{
    		++numring;
    	printf("\n\t (%d)   %c   %s %s %s , %s \n",numring,h,n_day,month,year,day);
    	fscanf(vw,"%s %s %s %s",&n_day,&month,&year,&day);
    
    	}
    	fclose(vw);
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void compare()
    
    {
    
    	FILE *ve,*vv,*tm,*tz,*se,*sp,*sz;
    	
    	char n_day[5],month[10],year[5],n_day1[5],month1[10],year1[5],day[10],first1[1],tourist1[1],q[1];
        int st=10,nd=40,n=0,k=0;
    	void filrename(),re_seat();
    	
    
    
    	ve=fopen("output.dat","r");
    	fscanf(ve,"%s %s %s %s",&n_day,&month,&year,&day);
    	
    		
    	while (!feof(ve))
    		
    	{
    	
    		
    		vv=fopen("seat_no.dat","r");
    		fscanf(vv,"%s %s %s %s %s",&n_day1,&month1,&year1,&first1,&tourist1);
    
    		se=fopen("no_seat.dat","r");
    		fscanf(se,"%s",&q);
    		
    		tz=fopen("temp.dat","w");
    		tm=fopen("temp.dat","a");
    
    		sz=fopen("no_seat1.dat","w");
    		sp=fopen("no_seat1.dat","a");
    		
    			
    		while (!feof(vv))
    		{
    			
    			
    			if ( (n_day1[0]==n_day[0] && n_day1[1]==n_day[1]) &&			
    				 (month1[0]==month[0] && month1[1]==month[1] &&month1[2]==month[2] &&month1[3]==month[3] &&
    				  month1[4]==month[4] &&month1[5]==month[5] &&month1[6]==month[6] &&month1[7]==month[8] &&
    				  month1[9]==month[9]) && 
    				 (year1[0]==year[0] && year1[1]==year[1] &&year1[2]==year[2] &&year1[3]==year[3] ) )
    					{
    						fprintf(tm,"%s %s %s %s %s \n",n_day1,month1,year1,first1,tourist1);
    						fprintf(sp,"%s \n",q);
    						break;
    						
    					}
    
    			else
    					{
    						++n;
    					}
    			
    			if (n==5)
    			
    			{
    				fprintf(tm,"%s %s %s %d %d \n",n_day,month,year,st,nd);
    				fprintf(sp,"%d \n",k);
    			}
                
    			
    		fscanf(vv,"%s %s %s %s %s",&n_day1,&month1,&year1,&first1,&tourist1);
    		fscanf(se,"%s \n",&q);
    				
    		}
    		n=0;
    		fscanf(ve,"%s %s %s %s",&n_day,&month,&year,&day);
    		fscanf(se,"%s",&q);
    		
    			
    	}
    
    	fcloseall();
    	filrename();
    	re_seat();
    	
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void filrename()
    {
    
    	char n_day2[5],month2[10],year2[5],first2[3],tourist2[2];
    	FILE *Fpin,*Fout,*Fout_2;
    	void enquiry();
    
    	
    	Fout=fopen("seat_no.dat","w.");
    	Fout_2=fopen("seat_no.dat","a");
    	Fpin=fopen("temp.dat","r");
        
    	fscanf(Fpin,"%s %s %s %s %s",&n_day2,&month2,&year2,&first2,&tourist2);
    
    	while (!feof(Fpin))
    		{
    			fprintf(Fout_2,"%s %s %s %s %s \n",n_day2,month2,year2,first2,tourist2);
    			fscanf(Fpin,"%s %s %s %s %s",&n_day2,&month2,&year2,&first2,&tourist2);
    			
    		}
    	
    
    
    fcloseall();
    enquiry();
    
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void re_seat()
    {
    
    	char seat[1];
    	FILE *pin,*out,*out_2;
    	
    	
    	out=fopen("no_seat.dat","w.");
    	out_2=fopen("no_seat.dat","a");
    	pin=fopen("no_seat1.dat","r");
        
    	fscanf(pin,"%s",&seat);
    
    	while (!feof(pin))
    		{
    			fprintf(out_2,"%s \n",seat);
    			fscanf(pin,"%s",&seat);
    			
    		}
    	
    
    
    fcloseall();
    
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void enquiry()
    
    {
    	char n_day[5],month[10],year[5],first[1],tourist[1];
    	FILE *vw;
    	int numring=0,h=16;
    
    	vw=fopen("seat_no.dat","r");
    	fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    		
    		while(!feof(vw))
    			{
    			++numring;
    			fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    			}
    
    }
    
    
    /*************************************************/
    
    /*************************************************/
    
    void main1()
    {
    	void header(),footer(),option1(),option2(),option3(),main(),loader();
    	int ans;
    	system("cls");
    	header();
    	printf("                              ---[ MAIN MENU ]--- \n\n\n\n");
    	printf("\t1. Enquiry System For Number And Type Of Seat Available\n\n");
    	printf("\t2. Book A Seat & Issue Ticket For Passenger\n\n");
    	printf("\t3. Output Passengers' list For Specific Flight\n\n");
        printf("\t4. Exit\n\n\n\n");
    	footer();
        printf("                    PLEASE ENTER YOUR CHOICE <1-4> : ");
    	scanf("%d",&ans);
    
    	switch(ans)
    		{
    			case 1:
    				system("cls");
    				option1();
    				break;
    
    			case 2:
    				system("cls");
    				option2();
    				break;
    
    			case 3:
    				system("cls");
    				option3();
    				break;
    
    			case 4:exit(1);
    
    			default:
    				    system("cls");
    		            header();
    		            printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    		            printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 4 IN THIS MENU     \n\n");
    					printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    					footer();
    					loader();
    					main1();
    					
    					
    					break;
    	
    		}
    
    
    	
    }
    /*************************************************/
    
    /*************************************************/
    void entrydat()
    {
    	void header();
    
    	header();
    	printf("                           ---[ TODAY'S DATE MENU ]--- \n\n\n");
    	
    	printf("\n NOTE : Format for date is e.g 12 Jan 2008\n\n\n\n\n"); 
    	printf("                     PLEASE ENTER TODAY'S DATE : 12 jan 2008 \n");
    
    	
    }
    
    /*************************************************/
    
    /*************************************************/
    void option1()
    {
    	void header(),footer(),display(),option1();
    	int ans,i,option1_2(int i);
    	system("cls");
    	header();
    	printf("                              ---[ ENQUIRY MENU ]--- \n\n");
    	printf("\n Below Are The Dates For Which There Are Flights:\n\n\n");
    
    	display();
    	printf("\n\n");
    	footer();
    	printf("          YOU ARE REQUESTED TO KEY IN THE INPUT OF YOUR CHOICE <1-5> : ");
    	scanf("%d",&ans);
    
    
    	switch(ans)
    		{
    			case 1:
    				i=1;
    				option1_2(i);
    				break;
    
    			case 2:
    				i=2;
    				option1_2(i);
    				break;
    
    			case 3:
    				i=3;
    				option1_2(i);
    				break;
    
    			case 4:
    				i=4;
    				option1_2(i);
    				break;
    
    			case 5:
    				i=5;
    				option1_2(i);
    				break;
    
    			default:
    				    system("cls");
    		            header();
    		            printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    		            printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 5 IN THIS MENU     \n\n");
    					printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    					footer();
    					loader();
    					option1();
    					
    					
    					break;
    	
    		}
    
    	
    }
    /*************************************************/
    
    /*************************************************/
    int option1_2(int i)
    {
    	void header(),footer(),option1(),main1();
    	int k=16,val=1,ans,st,nd,total;
    	FILE *vw;
    	char n_day[5],month[10],year[5],first[1],tourist[1];
    	vw=fopen("seat_no.dat","r");
    	
    	
    	fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    		
    		while(!feof(vw))
    			{
    			if (val==i)
    				break;
    			else
    				++val;
    				fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    
    			}
    	st=atoi(first);
    	nd=atoi(tourist);
    	total=st+nd;
    
    	system("cls");
        header();
    	printf("                         ---[ FLIGHT DETAILS' MENU ]--- \n\n\n");
    
    	printf("\n DATE SCHEDULED FOR : %s %s %s \n\n",n_day,month,year);
    	printf("\n TOTAL NUMBER OF SEAT(S) AVAILABLE: %d \n\n",total);
    	printf("\n\t %c TOURIST CLASS : %s SEAT(s) LEFT \n\n",k,tourist);
    	printf("\n\t %c FISRT CLASS   : %s SEAT(s) LEFT \n\n\n\n\n",k,first);
        footer(); 
    	printf("  ENTER <1> TO RETURN TO PREVIOUS MENU OR ENTER <2> TO RETURN TO MAIN MENU : ");
    	scanf("%d",&ans);
    
    	switch(ans)
    	{
    		case 1: 
    			option1();
    		break;
    		
    		case 2:
    			main1();
    			
    		break;
    
    		default:
    					system("cls");
    		            header();
    		            printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    		            printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    					printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    					footer();
    					loader();
    					option1();
    		break;
    	}
    
    	return(0);
    }
    
    /*************************************************/
    
    /*************************************************/
    void option2()
    {
    	void header(),footer(),option2_2(),display(),loader(),option2();
    	int ans,i,option2_3(int i);
    	system("cls");
    	header();
    	printf("                            ---[ BOOKING MENU ]--- \n\n");
    	printf("\n Below Are The Dates For Which Seats Are Bookable:\n\n\n");
    	display();
    	printf("\n\n");
    	footer();
    	printf("          YOU ARE REQUESTED TO KEY IN THE INPUT OF YOUR CHOICE <1-5> : ");
    	scanf("%d",&ans);
    
    
    
    	switch(ans)
    		{
    			case 1:
    				i=1;
    				option2_3(i);
    				break;
    
    			case 2:
    				i=2;
    				option2_3(i);
    				break;
    
    			case 3:
    				i=3;
    				option2_3(i);
    				break;
    
    			case 4:
    				i=4;
    				option2_3(i);
    				break;
    
    			case 5:
    				i=5;
    				option2_3(i);
    				break;
    
    			default:
    				    system("cls");
    		            header();
    		            printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    		            printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 5 IN THIS MENU     \n\n");
    					printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    					footer();
    					loader();
    					option2();
    					
    					
    					break;
    	
    		}
    
    
    }
    /*************************************************/
    
    /*************************************************/
    
    void option2_2(char dd[],char mm[],char yy[],int seat_typ)
    {
    	void header(),footer(),B_update(),main1(),option2_4();
    	int k=16,j=177,amount;
    	char ans,title[5],name[15],surname[15],seat[5];
    	FILE *nw;
    	system("cls");
    	header();
    	
    	if (seat_typ==2)
    	{
    		seat[0]='T';seat[1]='O';seat[2]='U';seat[3]='R';seat[4]='I';seat[5]='S';seat[6]='T';
    		amount=250;
    	}
    	
    	else
    	{
    
    		seat[0]='F';seat[1]='I';seat[2]='R';seat[3]='S';seat[4]='T';seat[5]=' ';seat[6]=' ';
    		amount=500;
    	}
    
    	printf("                            ---[ BOOKING MENU 2 ]--- \n\n\n\n");
    	printf("\n\t %c DATE OF FLIGHT          : %s %s %s \n",k,dd,mm,yy);
    	printf("\n\t %c TYPE OF SEAT OPTING FOR : %c%c%c%c%c%c%c Class\n",k,seat[0],seat[1],seat[2],seat[3],seat[4],seat[5],seat[6]);
    	printf("\n\t %c COST OF SEAT            : $ %d \n",k,amount);
    	printf("\n\t %c TITLE <Miss/Mrs/Mr>     : ",k);
    	scanf("%s",&title);
    	printf("\n\t %c FIRST NAME              : %c%c%c%c%c%c%c%c%c%c%c%c \b\b\b\b\b\b\b\b\b\b\b\b\b",k,j,j,j,j,j,j,j,j,j,j,j,j);
    	scanf("%s",&name);
    	printf("\n\t %c LAST NAME               : %c%c%c%c%c%c%c%c%c%c%c%c \b\b\b\b\b\b\b\b\b\b\b\b\b",k,j,j,j,j,j,j,j,j,j,j,j,j);
    	scanf("%s",&surname);
    	printf("\n\n\t N.B : Do Confirm This Reservation Only Upon Payment Duely Done . \n\n");
    	footer();
    	printf("                  CONFIRM BOOKING FOR THIS PASSNEGER ? <Y/N> : ");
    	scanf("%s",&ans);
    	ans=toupper(ans);
    	if (ans=='Y')
    	{
    	nw=fopen("book.dat","a");
    	fprintf(nw,"%s %s %s %s %s %s %c%c%c%c%c%c%c \n",dd,mm,yy,title,name,surname,seat[0],seat[1],seat[2],seat[3],seat[4],seat[5],seat[6]);
    	fclose(nw);
    	system("cls");
    	header();
    	printf("\n\n\n\t\t\t RESERVATION SUCCESFUL ! ! ! \n\n\n\t\t\t      Processing Data...\n\n\n\n");
    	B_update(dd,mm,yy,seat_typ);
    	loader();
    	option2_4(dd,mm,yy,title,name,surname,seat_typ);
    	main1();
    	}
    	else
    	{
    	system("cls");
    	header();
    		printf("\n\n\n\n \t\t\t RESERVATION ABORTED ! ! ! \n\n\n\n");
    	loader();
    	main1();
    	}
    }
    
    
    /*************************************************/
    
    /*************************************************/
    int option2_3(int i)
    {
    	void header(),footer(),main(),option2_2(),option2(),main1();
    	int k=16,val=1,ans,st,nd,option2_3(),seat_typ;
    	FILE *vw;
    	char n_day[5],month[10],year[5],first[1],tourist[1],reply;
    	vw=fopen("seat_no.dat","r");
    	
    	
    	fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    		
    		while(!feof(vw))
    			{
    			if (val==i)
    				break;
    			else
    				++val;
    				fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    
    			}
    	st=atoi(first);
    	nd=atoi(tourist);
    	
    
    	system("cls");
        header();
    	printf("                         ---[ BOOKING DETAILS' MENU ]--- \n\n\n");
    
    	printf("\n DATE SCHEDULED FOR : %s %s %s \n\n",n_day,month,year);
    	printf("\n\t (1) %c FISRT CLASS   : $ 500 \n\n",k);
    	printf("\n\t (2) %c TOURIST CLASS : $ 250 \n\n\n\n\n",k);
        footer(); 
    	printf("      ENTER <1> FOR A FIRST CLASS SEAT OR <2> FOR A TOURIST CLASS SEAT : ");
    	scanf("%d",&ans);
    
    	
    
    	switch(ans)
    		{
    		
    		case 1: 
    
    			if (st>0)
    			{	system("cls");
    				header();
    				printf("\t\tSeat Available,Proceeding with Booking...");
    				footer();
    				seat_typ=1;
    				option2_2(n_day,month,year,seat_typ);
    			}
    
    			if (st==0 && nd>0 )
    			{	system("cls");
    				header();
    				printf("\n\n\n\n\n\t\t Would You Prefer To Book For A Tourist Class Seat\n\n            Since There Is No First Class Seat Available On This Flight \n\n\t\t\t\t    <Y/N> : ");
    				getchar();
    				reply=toupper(getchar());
    						
    						switch(reply)
    						{
    							case 'Y':
    								seat_typ=2;
    								option2_2(n_day,month,year,seat_typ);
    								break;
    							case 'N':
    								printf("\n\n\n");
    								footer();
    								printf("   ENTER <1> TO BOOK SEAT ON ANOTHER FLIGHT OR <2> TO RETURN TO MAIN MENU : ");
    								scanf("%d",&ans);
    									switch(ans)
    									{
    										case 1 : 
    											 option2();
    										break;
    										
    										case 2 : 
    											 main1();
    
    										break;
    										
    										default:
    											 system("cls");
    											 header();
    											 printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    										     printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    											 printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    											 footer();
    					                         loader();
    											 main();
    
    										break;
    									}
    								
    								break;
    							default:
    								system("cls");
    								header();
    								printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    								printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    								printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    								footer();
    					            loader();
    								main();
    								break;
    							
    						}
    
    				
    			}
    
    			if (st==0 && nd==0)
    			{	
    				system("cls");
    				header();
    				printf("\n\n\n\t Sorry, There is neither First Class Seat Nor Tourist Class Seat \n\t\t\t    Available on This Flight ");
    				printf("\n\n\n");
    				footer();
    				printf("   ENTER <1> TO BOOK SEAT ON ANOTHER FLIGHT OR <2> TO RETURN TO MAIN MENU : ");
    				scanf("%d",&ans);
    								switch(ans)
    									{
    										case 1 : 
    											 option2();
    										break;
    										
    										case 2 : 
    											 main1();
    
    										break;
    										
    										default:
    											 system("cls");
    											 header();
    											 printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    										     printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    											 printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    											 footer();
    					                         loader();
    											 main();
    
    										break;
    									}
    
    			}
    
    		break;
    		
    		case 2:
    			if (nd>0)
    			{	system("cls");
    				header();
    				printf("\t\tSeat Available,Proceeding with Booking...");
    				seat_typ=2;
    				option2_2(n_day,month,year,seat_typ);
    			}
    
    			if (nd==0 && st>0 )
    			{	system("cls");
    				header();
    				printf("\n\n\n\n\n\t\t Would You Prefer To Book For A First Class Seat\n\n            Since There Is No Tourist Class Seat Available On This Flight \n\n\t\t\t\t    <Y/N> : ");
    				
    				getchar();
    				reply=toupper(getchar());
    						
    						switch(reply)
    						{
    							case 'Y':
    								seat_typ=1;
    								option2_2(n_day,month,year,seat_typ);
    								break;
    							case 'N':
    								printf("\n\n\n");
    								footer();
    								printf("   ENTER <1> TO BOOK SEAT ON ANOTHER FLIGHT OR <2> TO RETURN TO MAIN MENU : ");
    								scanf("%d",&ans);
    									switch(ans)
    									{
    										case 1 : 
    											 option2();
    										break;
    										
    										case 2 : 
    											 main1();
    
    										break;
    										
    										default:
    											 system("cls");
    											 header();
    											 printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    										     printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    											 printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    											 footer();
    					                         loader();
    											 main();
    
    										break;
    									}
    								
    								break;
    							default:
    								system("cls");
    								header();
    								printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    								printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    								printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    								footer();
    					            loader();
    								main();
    								break;
    							
    						}
    
    				
    			}
    			
    			if (nd==0 && st==0)
    			{	
    				system("cls");
    				header();
    				printf("\n\n\n\t Sorry, There is neither First Class Seat Nor Tourist Class Seat \n\t\t\t    Available on This Flight ");
    				printf("\n\n\n");
    				footer();
    				printf("   ENTER <1> TO BOOK SEAT ON ANOTHER FLIGHT OR <2> TO RETURN TO MAIN MENU : ");
    				scanf("%d",&ans);
    								switch(ans)
    									{
    										case 1 : 
    											 option2();
    										break;
    										
    										case 2 : 
    											 main1();
    
    										break;
    										
    										default:
    											 system("cls");
    											 header();
    											 printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    										     printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    											 printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    											 footer();
    					                         loader();
    											 main();
    
    										break;
    									}
    
    			}
    		break;
    
    		default:
    					system("cls");
    		            header();
    		            printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    		            printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 2 IN THIS MENU     \n\n");
    					printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    					footer();
    					loader();
    					option2_3(i);
    		break;
    	}
    
    	return(0);
    }
    
    /*************************************************/
    
    /*************************************************/
    void option2_4(char dd[],char mm[],char yy[],char title[],char name[],char surname[],int seat_typ)
    {
    	void header(),footer(),print();
    	char seat[5],ddd[5],mmm[5],yyy[5],fff[5],ttt[5],seat2[1];
    	int n=0,j=0,x=0;
    	FILE *fv,*pin,*out,*out_2;;
    	system("cls");
    	header();
    	
    	
    	if (seat_typ==2)
    	{
    		seat[0]='T';seat[1]='O';seat[2]='U';seat[3]='R';seat[4]='I';seat[5]='S';seat[6]='T';
    	}
    	
    	else
    	{
    
    		seat[0]='F';seat[1]='I';seat[2]='R';seat[3]='S';seat[4]='T';seat[5]=' ';seat[6]=' ';
    	}
    
    
    	fv=fopen("seat_no.dat","r");
    	fscanf(fv,"%s %s %s %s %s",&ddd,&mmm,&yyy,&fff,&ttt);
    
    	do
    		{
    		if ( (dd[0]==ddd[0] && dd[1]==ddd[1]) && (mm[0]==mmm[0] && mm[1]==mmm[1] && mm[2]==mmm[2]) 
    			  && (yy[0]==yyy[0] && yy[1]==yyy[1] && yy[2]==yyy[2] && yy[3]==yyy[3] ))
    			{
    				++n;
    				break;
    			}
    		else
    			fscanf(fv,"%s %s %s %s %s ",&ddd,&mmm,&yyy,&fff,&ttt);
    			++n;
    			
    			if (feof(fv)==16);
    			n=5;
    		}
    		while (!feof(fv));
    
    		
    
    
    	
    	fclose(fv);
    
    	out=fopen("no_seat.dat","w");
    	out_2=fopen("no_seat.dat","a");
    	pin=fopen("no_seat1.dat","r");
        
    	fscanf(pin,"%s",&seat2);
    	++j;
    
    	while (!feof(pin))
    		{
    		if (j==n)
    			{
    			x=atoi(seat2);
    			++x;
    			fprintf(out_2,"%d \n",x);
    			fscanf(pin,"%s",&seat2);
    			}
    		else
    			{
    			fprintf(out_2,"%s \n",seat2);
    			fscanf(pin,"%s",&seat2);
    			}
    		++j;
    			
    		}
    	
    fcloseall();
    
    
    
    	printf("                     ---[ PASSENGER'S TICKET PRINTOUT ]--- \n\n");
    	printf("\n DATE OF FLIGHT     : %s %s %s  \n",dd,mm,yy);
    	printf("\n DEPARTURE TIME     : 13:00     \n");
    	printf("\n ARRIVAL TIME       : 15:00     \n");
    	printf("\n FROM               : SSR National Airport,Mauritius \n");
    	printf("\n TO                 : Venise National Airport,Italy     \n");
    	printf("\n TYPE OF SEAT       : %c%c%c%c%c%c%c CLASS  \n",seat[0],seat[1],seat[2],seat[3],seat[4],seat[5],seat[6]);
    	printf("\n SEAT NUMBER        : %d \n",x);
    	printf("\n PASSENGER'S NAME   : %s %s %s \n",title,name,surname);
    
    	footer();
    	printf("\t\t       PRESS ANY KEY TO PRINT RECEIPT...    ");
    	getchar();getchar();
    	print();
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void B_update(char dd[],char mm[],char yy[],int seat_typ)
    
    {
    
    	FILE *vv,*tm,*tz;
    	
    	char n_day1[5],month1[10],year1[5],first1[1],tourist1[1];
        int st,nd;
    	void filrename();
    	
    
    
    		
    		vv=fopen("seat_no.dat","r");
    		fscanf(vv,"%s %s %s %s %s",&n_day1,&month1,&year1,&first1,&tourist1);
    		
    		tz=fopen("temp.dat","w");
    		tm=fopen("temp.dat","a");
    		
    			
    		while (!feof(vv))
    		{
    			st=atoi(first1);
    			nd=atoi(tourist1);
    			
    			
    			if ( (n_day1[0]==dd[0] && n_day1[1]==dd[1]) &&			
    				 (month1[0]==mm[0] && month1[1]==mm[1] &&month1[2]==mm[2] &&month1[3]==mm[3] &&
    				  month1[4]==mm[4] &&month1[5]==mm[5] &&month1[6]==mm[6] &&month1[7]==mm[7] &&
    				  month1[9]==mm[9]) && 
    				 (year1[0]==yy[0] && year1[1]==yy[1] &&year1[2]==yy[2] &&year1[3]==yy[3] ) )
    					{
    						if (seat_typ==2) 
    						fprintf(tm,"%s %s %s %d %d \n",n_day1,month1,year1,st,nd-1);
    						
    						if (seat_typ==1)
    						fprintf(tm,"%s %s %s %d %d \n",n_day1,month1,year1,st-1,nd);
    						
    												
    					}
    
    			else
    					{
    					
    						fprintf(tm,"%s %s %s %d %d \n",n_day1,month1,year1,st,nd);
    					}
                
    			
    		fscanf(vv,"%s %s %s %s %s",&n_day1,&month1,&year1,&first1,&tourist1);
    				
    		}
    		
    
    
    
    	fcloseall();
    	filrename();
    	
    }
    
    
    /*************************************************/
    
    /*************************************************/
    void option3()
    {
    	void header(),footer(),display(),option3_2(),option3();
    	int ans,i;
    	header();
    	printf("                    ---[ PASSENGERS' OUTPUT LIST MENU ]--- \n\n");
    	printf("\n Below Are The Dates For Which There is Flight:\n\n\n");
    
    	display();
    	printf("\n\n\n");
    	footer();
    	printf("          YOU ARE REQUESETD TO KEY IN THE INPUT OF YOUR CHOICE <1-5> : ");
    	scanf("%d",&ans);
    
    
    switch(ans)
    		{
    			case 1:
    				i=1;
    				option3_2(i);
    				break;
    
    			case 2:
    				i=2;
    				option3_2(i);
    				break;
    
    			case 3:
    				i=3;
    				option3_2(i);
    				break;
    
    			case 4:
    				i=4;
    				option3_2(i);
    				break;
    
    			case 5:
    				i=5;
    				option3_2(i);
    				break;
    
    			default:
    				    system("cls");
    		            header();
    		            printf("\n\n                     THERE WAS AN ERROR IN YOUR PREVIOUS INPUT             \n\n");
    		            printf("\n\n         YOU ARE REQUESTED TO INPUT ANY NUMBER FROM 1 TO 5 IN THIS MENU     \n\n");
    					printf("\n\n                    ANY OTHER INPUT WILL BE FLAGGED AS AN ERROR.              \n\n");
    					footer();
    					loader();
    					option3();
    					
    					
    					break;
    	
    		}
    
    	
    }
    
    /*************************************************/
    
    /*************************************************/
    
    void option3_2(int i)
    {
    	void header(),footer(),main1();
    	FILE *vw,*vq;
    	int val=1,numring=1,h=16,x=0;
    	char data1[5],data2[5],data3[5],data4[5],data5[10],data6[10],data7[10];
    	char n_day[2],month[5],year[5],first[1],tourist[1];
    	
    	system("cls");
    	header();
    
    	vw=fopen("seat_no.dat","r");
    	fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    		
    		while(!feof(vw))
    			{
    			if (val==i)
    				break;
    			else
    				++val;
    				fscanf(vw,"%s %s %s %s %s",&n_day,&month,&year,&first,&tourist);
    
    			}
    
    
    	fclose(vw);
    
    	printf("                       ---[ PASSENGERS' OUTPUT LIST ]--- \n\n");
    	printf("\n Below Is The List Of Passengers For The Flight Scheduled For : %s %s %s\n",n_day,month,year);
    	printf("\n Departure Time : 13:00 \n");
    	printf("\n Arrival   Time : 15:00 \n");
    	printf("\n From           : SSR National Airport,Mauritius \n");
    	printf("\n To             : Venise National Airport,Italy  \n\n\n");
    
    	vq=fopen("book.dat","r");
    	
    	fscanf(vq,"%s %s %s %s %s %s %s",&data1,&data2,&data3,&data4,&data5,&data6,&data7);
    		
    		while(!feof(vq))
    			{
    			if ((data1[0]==n_day[0] && data1[1]==n_day[1] && data1[2]==n_day[2]) && (data1[0]==n_day[0] &&data1[1]==n_day[1] && data1[2]==n_day[2]) &&( data3[0]==year[0] && data3[1]==year[1] && data3[2]==year[2] && data3[3]==year[3] ))
    			{
    				printf("\n\t (%d) %c%c%c%c%c %s %s %s | SEAT ClASS : %s \n",numring,h,h,h,h,h,data4,data5,data6,data7);
    			++numring;
    			++x;
    			}
    			
    			fscanf(vq,"%s %s %s %s %s %s %s",&data1,&data2,&data3,&data4,&data5,&data6,&data7);
    			
    			}
    printf("\n\n\n\t      Total Number Of Passenger(s) aboard This Flight : %d ",x);
    
    if ( (feof(vq)==16) && (x==0) )
    printf("\n\n\n \t      %c No Passenger Has Book For Any Seat On This Flight\n\n",h);
    
    	fcloseall();
    	printf("\n\n");
    	footer();
    	printf("\t\t      PRESS ANY KEY TO RETURN TO MAIN MENU");
    	getchar();getchar();
    	main1();
    }
    
    /*************************************************/
    
    /*************************************************/
    void header()
    
    {
    	int k,n=0;
    
    	k=201;
    	printf("%c",k);
    	
    	k=205;
    
    	while (n<=77)
    	{
    		printf("%c",k);
    			++n;
    
    	}
    	
    	k=187;
    	printf("%c",k);
    
    
    	k=186;
    	printf("%c                                                                              %c",k,k);
    	printf("%c                     BRITISH AMERICAN TRAVEL COMPANY LTD                      %c",k,k);
    	printf("%c                                                                              %c",k,k);
    
    
        k=200;
    	printf("%c",k);
    
    	
        k=205;
    	n=0;
    
    	while (n<=77)
    	{
    		printf("%c",k);
    			++n;
    
    	}
    
    	k=188;
    	printf("%c",k);
    
    		
    
    }
    
    /*************************************************/
    
    /*************************************************/
    void footer()
    
    {
    	int n=0,k;
    		
    	k=196;
    	printf("\n");
    
    	while (n<=79)
    	{
    		printf("%c",k);
    			++n;
    
    	}
    
    
    }
    
    void loader()
    {
    long int j,k,ld=219,un;
    
    printf("\n\n\n                                   LOADING ...\n");
    for (j=0;j<=79;++j)
    
    {
    	
    	printf("%c",ld);
    	
    
    	for (k=0;k<=30000000;++k)
    	{
    	++un;
    	}
    
    }	
    
    printf("\n");
    
    }
    
    void print()
    {
    long int j,k,ld=219,un;
    
    printf("\n\n\n                                   PRINTING ...\n");
    for (j=0;j<=79;++j)
    
    {
    	
    	printf("%c",ld);
    	
    
    	for (k=0;k<=30000000;++k)
    	{
    	++un;
    	}
    
    }
    
    }

  15. #45
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    How about you do a little to narrow down the program? Noone wants to go through all that for you.
    Better yet, learn how to use debuggers.
    And learn not to hijack threads.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. Checking maximum values for dynamic array...
    By AssistMe in forum C Programming
    Replies: 1
    Last Post: 03-21-2005, 12:39 AM
  5. Replies: 5
    Last Post: 05-30-2003, 12:46 AM