Help Needed

Discussion in 'C Programming' started by den_cse_here@yahoo.com, Jul 25, 2006.

  1. Guest

    Hello,
    I've to take the input from a file in which data will be something like
    this:

    FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    DESC~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+
    FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    DESC~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+



    I wrote the following code snippet to extract the data from the file:

    flag = FALSE;

    while(fgets(input,MAX-1,stream)!=0)
    {
    if(flag == FALSE)
    {
    sscanf(input,

    "%[A-Z]~!+%[a-zA-Z0-9]~!+%d~!+%[A-Z]~!+%[A-Z]~!+%[A-Z]~!+%[A-Z0-9]~!+%[A-Z0-9]",
    service, RR, &priority,Note, Port1, Port2, Route_code,
    Route_code_desc);

    flag = TRUE;

    printf("%s %s %d %s %s %s %s %s\n",service,RR,
    priority,Note,Port1,Port2,Route_code,Route_code_desc);

    } // if ends here.

    else // flag was TRUE.
    {

    sscanf(input,"%[A-Z]~!+%[A-Z]~!+%[A-Z]~!+%[A-Z0-9]~!+%[A-Z0-9]",
    temp,Port1, Port2, Route_code,Route_code_desc);

    if(strcmp(Port1,"") ==0)
    {
    flag = TRUE;
    }

    else
    {
    printf("%s %s %s %s %s\n",temp,Port1, Port2,
    Route_code,Route_code_desc);
    }

    } // outer else part ends here.

    } // While loop ends here.



    I DON'T KNOW WHY THE ABOVE CODE IS GIVING ME THIS IN THE OUTPUT .
    Specifically, I don't know why the code is ignoring the SG001 part in
    the second loop

    FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    FENC~!+SG
    DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2

    Can anybody please help me to sort out the problem?

    Thanks.
     
    , Jul 25, 2006
    #1
    1. Advertising

  2. On Tue, 25 Jul 2006 wrote:

    > Hello,
    > I've to take the input from a file in which data will be something like
    > this:
    >
    > FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    > DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    > DESC~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+
    > FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    > DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    > DESC~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+
    >
    >
    >
    > I wrote the following code snippet to extract the data from the file:
    >
    > flag = FALSE;
    >
    > while(fgets(input,MAX-1,stream)!=0)
    > {
    > if(flag == FALSE)
    > {
    > sscanf(input,
    >
    > "%[A-Z]~!+%[a-zA-Z0-9]~!+%d~!+%[A-Z]~!+%[A-Z]~!+%[A-Z]~!+%[A-Z0-9]~!+%[A-Z0-9]",
    > service, RR, &priority,Note, Port1, Port2, Route_code,
    > Route_code_desc);
    >
    > flag = TRUE;
    >
    > printf("%s %s %d %s %s %s %s %s\n",service,RR,
    > priority,Note,Port1,Port2,Route_code,Route_code_desc);
    >
    > } // if ends here.
    >
    > else // flag was TRUE.
    > {
    >
    > sscanf(input,"%[A-Z]~!+%[A-Z]~!+%[A-Z]~!+%[A-Z0-9]~!+%[A-Z0-9]",
    > temp,Port1, Port2, Route_code,Route_code_desc);
    >
    > if(strcmp(Port1,"") ==0)
    > {
    > flag = TRUE;
    > }
    >
    > else
    > {
    > printf("%s %s %s %s %s\n",temp,Port1, Port2,
    > Route_code,Route_code_desc);
    > }
    >
    > } // outer else part ends here.
    >
    > } // While loop ends here.
    >
    >
    >
    > I DON'T KNOW WHY THE ABOVE CODE IS GIVING ME THIS IN THE OUTPUT .
    > Specifically, I don't know why the code is ignoring the SG001 part in
    > the second loop
    >
    > FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    > DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    > FENC~!+SG
    > DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    >
    > Can anybody please help me to sort out the problem?
    >
    > Thanks.


    You have forgotten to set flag to FALSE in the appropriate
    places.

    Tak-Shing
     
    Tak-Shing Chan, Jul 25, 2006
    #2
    1. Advertising

  3. Eric Sosman Guest

    wrote On 07/25/06 15:21,:
    > Hello,
    > I've to take the input from a file in which data will be something like
    > this:
    >
    > FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    > DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    > DESC~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+
    > FENC~!+SG001~!+1~!+TEST DATA~!+SGSIN~!+KRPUS~!+LOOP1~!+LOOP1
    > DESC~!+KRPUS~!+GBSOU~!+LOOP2~!+LOOP2
    > DESC~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+~!+
    >
    >
    >
    > I wrote the following code snippet to extract the data from the file:
    >
    > flag = FALSE;
    >
    > while(fgets(input,MAX-1,stream)!=0)


    You haven't shown how `input' is declared, but if it's
    equivalent to `char input[MAX]' then you can use MAX instead
    of MAX-1 here. If `input' is an actual array (not a pointer),
    it would be even better to write `sizeof input' as the
    second argument.

    > {
    > if(flag == FALSE)
    > {
    > sscanf(input,
    >
    > "%[A-Z]~!+%[a-zA-Z0-9]~!+%d~!+%[A-Z]~!+%[A-Z]~!+%[A-Z]~!+%[A-Z0-9]~!+%[A-Z0-9]",
    > service, RR, &priority,Note, Port1, Port2, Route_code,
    > Route_code_desc);
    >
    > flag = TRUE;
    >
    > printf("%s %s %d %s %s %s %s %s\n",service,RR,
    > priority,Note,Port1,Port2,Route_code,Route_code_desc);
    >
    > } // if ends here.
    >
    > else // flag was TRUE.
    > {
    >
    > sscanf(input,"%[A-Z]~!+%[A-Z]~!+%[A-Z]~!+%[A-Z0-9]~!+%[A-Z0-9]",
    > temp,Port1, Port2, Route_code,Route_code_desc);
    >
    > if(strcmp(Port1,"") ==0)
    > {
    > flag = TRUE;


    Do you mean FALSE here?

    > }
    >
    > else
    > {
    > printf("%s %s %s %s %s\n",temp,Port1, Port2,
    > Route_code,Route_code_desc);
    > }
    >
    > } // outer else part ends here.
    >
    > } // While loop ends here.
    >
    >
    >
    > I DON'T KNOW WHY THE ABOVE CODE IS GIVING ME THIS IN THE OUTPUT .
    > Specifically, I don't know why the code is ignoring the SG001 part in
    > the second loop


    "The second loop?" I see only one ...

    --
     
    Eric Sosman, Jul 25, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andy

    urgent help needed !

    andy, Jul 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    912
  2. Thomas Nick
    Replies:
    0
    Views:
    1,889
    Thomas Nick
    Jun 13, 2005
  3. Ryan Macy

    Ideas needed & help needed!

    Ryan Macy, Jul 19, 2006, in forum: Ruby
    Replies:
    2
    Views:
    518
    Ryan Macy
    Jul 19, 2006
  4. LeTubs
    Replies:
    6
    Views:
    125
    Tad McClellan
    Jan 25, 2004
  5. John Farold
    Replies:
    0
    Views:
    387
    John Farold
    Aug 29, 2012
Loading...

Share This Page