Help with my code!!!


 
Thread Tools Search this Thread
Top Forums Programming Help with my code!!!
# 1  
Old 05-09-2013
Help with my code!!!

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "declarationLibrary.h"


void checkIn(void)
{ 

flight_data record[200];
reservation brecord[200];
FILE *fp1;
FILE *fp2;
char line[200];
char line_2[200];
char*item;
char*item_2;
int flight=0;
int book=0;
int i;
char fname[20];
char lname[20];
int m;
int op;

    



        printf("------------------------------------------------------------\n");
        printf("                        Checking a passenger  \n");
        printf("------------------------------------------------------------\n");


            /*Employee enters customers name*/

         printf("Please enter first name: \n");
             scanf("%s",fname);
        printf("Please enter last name: \n");
        scanf("%s",lname);
        printf("Name:%s%s\n",fname,lname);






     /*Opening the two files file*/
        fp1=fopen("flight.txt","r");
        fp2=fopen("booking.txt","r");
     
    printf("Opened file\n");

        if(fp1 == NULL)
        {
            printf("Error opening the file flight\n");
        }
    else if(fp2 == NULL)
        {
            printf("Error opening the file booking\n");
        }
    
    
        
        /*Read the file line by line for flight*/

        while(fgets(line,200,fp1))
        {    
            item=strtok(line," ");
            strcpy(record[flight].flightNo,item);

            item=strtok(NULL," ");
               strcpy(record[flight].source,item);

            item=strtok(NULL," ");
            strcpy(record[flight].destination,item);

            item=strtok(NULL," ");
            record[flight].departure=atof(item);

            item=strtok(NULL," ");
            record[flight].arrival=atof(item);
        
        item=strtok(NULL," ");
            strcpy(record[flight].date,item);

            flight++;

        }

         /*Close the file*/
             fclose(fp1);

        /*Read the file line by line for booking*/

    while(fgets(line_2,200,fp2))
        {
            item_2=strtok(line_2," ");
            strcpy(brecord[book].firstname,item_2);

        item_2=strtok(NULL," ");
            strcpy(brecord[book].lastname,item_2);
    
            item_2=strtok(NULL," ");
            strcpy(brecord[book].flightNo,item_2);

            book++;
        
         }

        /*Close the file*/
            fclose(fp2);
    
    
        
        /*Print the flight details*/

        for(i=0; i<book; i++)
        {
    

            
        
                if((strcmp(fname,brecord[i].firstname))==0)
            {
                if((strcmp(lname,brecord[i].lastname))==0)
                {
    
                    printf("FlightNo: %s\n",record[i].flightNo);
                    printf("Source: %s\n",record[i].source);
                    printf("Destination: %s\n",record[i].destination);
                    printf("Departure: %.2f\n",record[i].departure);
                    printf("Arrival: %.2f\n",record[i].arrival);
                printf("Date: %s\n",record[i].date);

                }
                else
                {
                    printf("Please try again\n");        
                    checkIn();
                    
                }
                
        
            }        
            
                

        }
        


        /*Confirmation for checking*/
          printf("Press 3 to to confirm check in: ");
          scanf("%d",&m);

            if(m==3)
              {
                printf("%s %s has checked in\n",fname,lname);
                
               }        
            


        printf("Press 8 to to check in another passenger or 9 to quit:\n");
        scanf("%d",&op);    
        
        if(op==8)
        {
             checkIn();
        }
        else 
        {
            return;
        }





}

My objective is when the staff enters inputs the customers name it should open the file and read the file line by line. Then it should print the customers flight details.

Where it says
Code:
/*fp2=fopen("booking.txt","r");*/

for some reason it's not readinfg the file properly. I have saved the file as booking.txt . Does anyone have any ideas on how to fix this problem

Last edited by Scrutinizer; 05-09-2013 at 06:23 AM.. Reason: code tags
# 2  
Old 05-09-2013
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums. Adding exclamation marks to your title gives it a sense of urgency...

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Linux

Go to a line of code , skip few lines of code

Hi , I have a code where i am using a infinite while loop . some thing like below while do if then #go to line 20 fi command 1; command 2; #line 20: sleep 34; (5 Replies)
Discussion started by: Paarth
5 Replies

2. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

3. UNIX for Dummies Questions & Answers

If ‘922’ Code does not exist on ‘03’ Record, ‘901’ Code will be there instead, move ‘03’ R

01,011600033,011600033,110516,0834,2,90,,2/ 02,011600033,011103093,1,110317,0834,,2/ 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+000000 00354,,/ 03,113806,,015,+00000559618,,,901,+00000000096,,,922,+000000 00621,,/ 88,902,+0000000025218,,/... (1 Reply)
Discussion started by: sgoud
1 Replies

4. Shell Programming and Scripting

translate ksh code to csh code

hi all, Can any 1 help me translate this korn shell code to C shell code : email=$(grep "^$1" $folder/config_2.txt | awk '{print $2'}) In config_2.txt the content is : which mean in korn shell , $1=groupname and $2=email address. Now i need to write in C shell script,when i set the... (2 Replies)
Discussion started by: proghack
2 Replies

5. Programming

how i prepare a c++ code(c code) for implementing my own protocol format

helo my protocol format is given below { destno,mode,no.of packet,pktsize,,pktno,textsize,CRC} description:- { is starting flag destno - 4bytes mode - 1 byte no.of pkt - 4byes pktsize - 6 bytes ... (1 Reply)
Discussion started by: amitpansuria
1 Replies

6. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question