printf似乎在覆盖自己

时间:2015-09-20 04:02:44

标签: c

所以我正在尝试格式化这一行

******************* Flight Reservation Request  **********************
 email name (M 1986/01/01)

但所有打印的都是

******************* Flight Reservation Request  **********************
 (M 1986/01/01)

执行此操作的代码是

FILE * pFileCust; // stream Input for Customer Reservation data
void processCommandSwitches(int argc, char * argv[], char * * ppszCustomerFileName);
void processReservations();
int main(int argc, char * argv[]) {
    char * pszCustomerFileName = NULL;
    // Process the command switches
    processCommandSwitches(argc, argv, & pszCustomerFileName);
    // open the Customer Reservation stream data file
    if (pszCustomerFileName == NULL)
        exitError(ERR_MISSING_SWITCH, "-c");
    pFileCust = fopen(pszCustomerFileName, "r");
    if (pFileCust == NULL)
        exitError(ERR_CUSTOMER_RES_FILENAME, pszCustomerFileName);
    // process the Reservations
    processReservations();
    fclose(pFileCust);
    printf("\n"); // included so that you can put a breakpoint on this line
    return 0;
}
/****** you need to document and code this function *****/
void processReservations() {
    rewind(pFileCust);
    char gender[1];
    char dob[11];
    char emailAddress[53];
    char fullName[31];
    char address[31];
    char city[21];
    char state[31];
    char zip[61];
    fscanf(pFileCust, "%s %s %s %31[^\n]", gender, dob, emailAddress, fullName);
    printReservations(emailAddress, fullName, gender, dob, address, city, state, zip);
}
printReservations(char email[], char name[], char gender[], char dob[], char address[], char city[], char state[], char zip[]) {
    printf("******************* Flight Reservation Request  **********************\n");
    printf("%s %s (%s %s)\n", email, name, gender, dob);
}

输入文件

M 1986/01/01 petem@xyz.net Pete Moss
123 Boggy Lane,New Orleans,LA,70112
H100.15005 2      
H222.15005 2
H200.15010 2
H333.15010 2       
END 0
M 1957/02/02 pcorn@abc.netPopCorn______________________
456 Kernel,San Antonio,TX,78210
H222.15005 10
HXXX.XXXXX 10
H333.15010 5
END 0
F 1958/03/03 pennyl@xyz.net Penny Loafer
789 Walking St,Philadelphia,PA,19102
H444.15001 1
H333.15010 1
END 0
M 1979/04/04 hgilmore@xyz.net Adam Sandler
444 Golf View,Hollywood,CA,92274
H100.15005 3
END 0
F 1989/05/05 butter@xyz.net Melba Toast
222 Cracker Blvd,San Antonio,TX,78222 
H333.15010 2
H444.15015 2
END 0

0 个答案:

没有答案