473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help Needed

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_de sc);

} // 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 '06 #1
2 1339
On Tue, 25 Jul 2006 de**********@yahoo.com 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_de sc);

} // 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
Jul 25 '06 #2


de**********@yahoo.com 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_de sc);

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

--
Er*********@sun.com

Jul 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
7
by: ChadDiesel | last post by:
Hello everyone, I'm having a problem with Access that I need some help with. The short version is, I want to print a list of parts and part quantities that belong to a certain part group---One...
7
by: Tina | last post by:
I have an asp project that has 144 aspx/ascx pages, most with large code-behind files. Recently my dev box has been straining and taking long times to reneder the pages in the dev environment. ...
10
by: Mae Lim | last post by:
Dear all, I'm new to C# WebServices. I compile the WebService project it return no errors "Build: 1 succeeded, 0 failed, 0 skipped". Basically I have 2 WebMethod, when I try to invoke the...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
2
by: Steve K | last post by:
I got a bit of a problem I like some help on. I'm designing an online training module for people that work in food processing plants. This is my target audience. These workers have little or no...
3
by: Kitana907 | last post by:
Hi- I'm attempting to write a module that uses and updates info from two tables and does the following: Opens the recordset of a table called "tblstoreinv" If the Needed Field in the...
9
by: smartbei | last post by:
Hello, I am a newbie with python, though I am having a lot of fun using it. Here is one of the excersizes I am trying to complete: the program is supposed to find the coin combination so that with...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.