Help Needed

D

den_cse_here

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.
 
T

Tak-Shing Chan

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
 
E

Eric Sosman

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 ...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top