我有一个文本文件,其中包含一系列出发日期的航班信息 . (将链接文本文件)我需要将该文本文件拆分为多个文本文件,其中每个创建的文本文件只有一个特定的航空公司 . 应该创建4个文本文件,因为有AA,DL,OO和F航空公司 . 这意味着需要创建的四个文本文件是AA.txt,DL.txt,OO.txt和F.txt,并且在每个文本文件中应该只有其特定的航空公司 . 因此AA.txt中应该只有美国航空公司航班,没有其他航班等.C中的代码是什么样的?

这是我到目前为止:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    FILE *fp1;
    char* arr[4] = {"AA", "DL", "OO", "F"};
    char airLine[350];
    char line[120];
    int noLine = 0;
    char **str = NULL;

    printf("Enter input file name:");
    scanf("%s", airLine);

    fp1 = fopen(airLine,"r");
    if (!fp1)
    {
        return 1;
    }
    while(fgets(airLine, sizeof(airLine), fp1) != NULL)
    {
        if(strchr(airLine, '\n'))
        airLine[strlen(airLine)-1] = '\0';
        str = (char**)realloc(str, sizeof(char**)*(noLine+1));
        str[noLine] = (char*)calloc(350, sizeof(char));
        strcpy(str[noLine], airLine);
        noLine++;
    }
    for()
    {

    }
}

这是我认为需要在c中的代码中发生的事情 .

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    FILE *fp1;
    char* str[6] = {"AA", "DL", "OO", "F"};
    // want to have the first 2 characters don't know how
    char airLine[350];
    char line[120];

    printf("Enter input file name:");
    scanf("%s", airLine);

    fp1 = fopen(airLine,"r");
    if (!fp1)
    {
       return 1;
    }

    while(fgets(airLine, sizeof(airLine), fp1) != NULL)
    {
        if(// if the first 2 characters of airline doesn't exist inarray)             
        // write unknown characters in the array that are in the text
        // file otherwise do nothing
    }
    for(// iterate through the list of the collected string)
    {
        sprintf(line, ".txt");
        fp2 = fopen(line, "w");
        while(fgets(line, sizeof(line), fp2) != NULL)
        {
            if(// If the airline matches the airline in the current txt     file)
            // Then write the airline and create the file otherwise do nothing
            // prob fprintf maybe
        }
        // maybe close fp2 in here
    }
    fclose(fp1);
    fclose(fp2);
    return 0;
}

这是文本文件:

AA43 DFW DTW 2016-01-06 11:00
AA43 DFW DTW 2016-01-17 11:00
AA44 SEA JFK 2015-02-05 7:45
AA197 ORD BOS 2012-03-12 11:50 
AA1 JFK LAX 2016-07-02 9:00
OO7435 DTW PLN 2016-11-22 21:55
F9612 DEN MIA 2014-12-19 22:15
DL801 GEG MSP 2016-08-31 9:00
DL1087 ATL DAB 2016-04-10 12:05
DL828 IAH SLC 2012-06-02 7:45