0

I want to set two tokens so that every time a EBO has a DWG then I would want to either load them both to a array or write them both out to a text file with some sort of delimiter. In C++

Sample Data:

1~EBOA54_5047734~7-554440039DWG~
2~EBOA54_5045445~7-544440304DWG~
3~EBOA54_5045445~7-544440303DWG~
4~EBOA54_5047939~7-344443445DWG~
5~EBOA54_5047770~7-454440054DWG~
6~EBOA54_5045048~7-344443484DWG~
7~EBOA54_5045444~7-344440300DWG~
8~EBOA54_5047833~7-553447500DWG~
9~EBOMPS_5040395~ ~
10~EBOMPS_5040385~ ~
11~EBOA54_5048008~7-544A44574DWG~
12~EBOMPS_5040387~ ~
13~EBOMPS_5040394~ ~
14~EBOMPS_5040394~ ~
15~EBOMPS_5040395~ ~
16~EBOMPS_5040487~ ~
17~EBOA54_5045075~7-444440444DWG~
18~EBOA54_5047748~7-344444043DWG~
19~EBOA54_5047475~7-344450444DWG~
20~EBOMPS_5040404~ ~
21~EBOMPS_5040397~ ~
22~EBOMPS_5040375~ ~
23~EBOMPS_5040383~ ~
24~EBOMPS_5040404~ ~
25~EBOMPS_5040403~ ~
26~EBOMPS_5040444~ ~
27~EBOMPS_5040378~ ~
28~EBOMPS_5040444~ ~
29~EBOMPS_5040398~ ~
30~EBOMPS_5040447~ ~
31~EBOA54_5048404~7-344440000DWG~
32~EBOA54_5047954~ ~
33~EBOA54_5047995~7-344540049DWG~
34~EBOMPS_5040407~ ~
35~EBOA54_5047845~7-344450440DWG~
36~EBOMPS_5040375~ ~
37~EBOA54_5047549~7-344534444DWG~
38~EBOA54_5048444~7-544A44408DWG~
39~EBOA54_5048444~7-344444044DWG~
40~EBOMPS_5040448~ ~
41~EBOMPS_5040444~ ~
42~EBOA54_5048445~7-544A44598DWG~
43~EBOMPS_5040408~ ~
44~EBOMPS_5040449~ ~
45~EBOMPS_5040444~ ~
46~EBOMPS_5040443~ ~

POSSIBLE SAMPLE OUTPUT 1:

EBOA54_5047734~7-554440039DWG
EBOA54_5045445~7-544440304DWG
etc..

POSSIBLE SAMPLE OUTPUT 2:

Array 1-EBOA54_5047734,EBOA54_5045445,EBOA54_5045445,EBOA54_5047939, etc..

Array 2-7-554440039DWG,7-544440304DWG,7-544440303DWG,7-344443445DWG, etc..

My intent is to compare the DWG number to another file that is in the same format so I can determine if the EBO number has changed over time. The length of the strings and the starting characters can change over time so no specific character can be hard coded. It has to be based off of the delimiter. It can be written to a text file like what my code listed below is trying to do or written to a array. If it is written to a array then I don't want the ~ tildes added to the array.

CODE ATTEMPT:

void extract_xml_ebo_dwg()
{



    int  uu = 0;
    int   j;
    char *y = 0;
    char data_field[25][50];
    char delimiter;

    fgets(Test_line_in, LINESZ, xml_ebo_dwg_file);

        strcpy(testebo_work_line, Test_line_in);
        y=strtok(testebo_work_line, "~");
        j = 0;

        while(y)
        {
            j++;
            if(j==1)
            {
                strcpy (ebo_index, y);
                             }

                y = strtok(NULL,"~");
                if(ebo_index)
                {
                strcpy(line_out, ebo_index);
                printf(ebo_index);
                strcat(line_out,"~");
                fprintf(Testfileout1, line_out);
                }


            if(j==2)
            {
                strcpy (DWG_id, y); 
            }
                y = strtok(NULL,"~");
                if(DWG_id != " ")
                {
                strcpy(line_out, DWG_id);
                printf(DWG_id);
                strcat(line_out, "~");
                fprintf(Testfileout1, line_out);
                }
R Sahu
  • 204,454
  • 14
  • 159
  • 270

1 Answers1

0

I don't think you worded this very well but let me say how I'd approach it.

I'd start by looking at a bunch of data. Make sure that your assumptions about the data don't have exceptions.

Looking at the data, I'd want to take it line by line. To simplify things, read each line into a buffer and then work with that buffer.

Looking at a single line, I can see there are 3 tilde characters. The C library offers several functions for locating these so start by getting the position of them.

If there is nothing but whitespace between the 2nd and 3rd tilde, then it looks like that line has no "DWG". It sounds like you are ignoring such lines.

Otherwise, you have two string values. You know where they are because they fall between the tildes, which you have the positions of. It should be very trivial to extract them at this point and do whatever you'd like with them.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466