Computer hangs in while loop 
Author Message
 Computer hangs in while loop

I've got a DOS app written in C that runs on low end PC's.  One part of this
app copies values in a data file.  For example, if my data file looked like
the following:
FIELD1      FIELD2
A                    1
A                    2
A                    3
Now, I want to copy this data, creating 3 new rows in the data file that
look like this:
B                    1
B                    2
B                    3
So, that's what this function is supposed to do.  I'm having a problem with
the computer{*filter*} after 4-5 iterations through the loop.  The following
code is the while loop that is causing problems.  Does anyone see a problem
here:  Thanks for any help!!!
      while(i <= 10)
      {
         if (FirstRec == NULL)
         {
            FirstRec = malloc( sizeof( struct rLabel ) + 1 );
            NextRec = FirstRec;
            sprintf(tempPoint, "%s", f4str(f4BPoint));
            sprintf(NextRec -> bPoint, "%s", tempPoint + 4);
            sprintf(NextRec -> pLabel, "%s", f4str(f4PLabel));
            NextRec -> Next = NULL;
         }
         else
         {
            NextRec -> Next = malloc( sizeof( struct rLabel ) + 1 );
            NextRec = NextRec -> Next;
            sprintf(tempPoint, "%s", f4str(f4BPoint));
            sprintf(NextRec -> bPoint, "%s", tempPoint + 4);
            sprintf(NextRec -> pLabel, "%s", f4str(f4PLabel));
            NextRec -> Next = NULL;
         }
         dbNext(d4Labels);
         strncpy(tempType, f4str(f4BPoint), 4);
         tempType[4] = '\0';
       i++;
      }



Mon, 18 Sep 2000 03:00:00 GMT  
 Computer hangs in while loop

How are your structure look like ?
What I think is, your loop looks ok, but what about the length of your
variable ?
ex.
Is there enough space in tempPoint to hold the data ?
Is there enough space in NextRec -> bPoint ?
Is there enough space in NextRec -> pLabel ?
Is there enough space in tempType ? if you use tempType[4]='\0';, it means
that you have define as "char tempType[5]"

Quote:

>I've got a DOS app written in C that runs on low end PC's.  One part of
this
>app copies values in a data file.  For example, if my data file looked like
>the following:
>FIELD1      FIELD2
>A                    1
>A                    2
>A                    3
>Now, I want to copy this data, creating 3 new rows in the data file that
>look like this:
>B                    1
>B                    2
>B                    3
>So, that's what this function is supposed to do.  I'm having a problem with
>the computer{*filter*} after 4-5 iterations through the loop.  The following
>code is the while loop that is causing problems.  Does anyone see a problem
>here:  Thanks for any help!!!
>      while(i <= 10)
>      {
>         if (FirstRec == NULL)
>         {
>            FirstRec = malloc( sizeof( struct rLabel ) + 1 );
>            NextRec = FirstRec;
>            sprintf(tempPoint, "%s", f4str(f4BPoint));
>            sprintf(NextRec -> bPoint, "%s", tempPoint + 4);
>            sprintf(NextRec -> pLabel, "%s", f4str(f4PLabel));
>            NextRec -> Next = NULL;
>         }
>         else
>         {
>            NextRec -> Next = malloc( sizeof( struct rLabel ) + 1 );
>            NextRec = NextRec -> Next;
>            sprintf(tempPoint, "%s", f4str(f4BPoint));
>            sprintf(NextRec -> bPoint, "%s", tempPoint + 4);
>            sprintf(NextRec -> pLabel, "%s", f4str(f4PLabel));
>            NextRec -> Next = NULL;
>         }
>         dbNext(d4Labels);
>         strncpy(tempType, f4str(f4BPoint), 4);
>         tempType[4] = '\0';
>       i++;
>      }



Tue, 19 Sep 2000 03:00:00 GMT  
 Computer hangs in while loop

Franky,

Here's what my declarations look like:

char tempPoint[9];
char tempType[9];

The structure is defined as:

struct rLabel
{
    char bPoint[9];
    char pLabel[16];
    struct rLabel *Next;

Quote:
};

Does this info help?

Thanks,
Jeff

Quote:

>How are your structure look like ?
>What I think is, your loop looks ok, but what about the length of your
>variable ?
>ex.
>Is there enough space in tempPoint to hold the data ?
>Is there enough space in NextRec -> bPoint ?
>Is there enough space in NextRec -> pLabel ?
>Is there enough space in tempType ? if you use tempType[4]='\0';, it means
>that you have define as "char tempType[5]"


>>I've got a DOS app written in C that runs on low end PC's.  One part of
>this
>>app copies values in a data file.  For example, if my data file looked
like
>>the following:
>>FIELD1      FIELD2
>>A                    1
>>A                    2
>>A                    3
>>Now, I want to copy this data, creating 3 new rows in the data file that
>>look like this:
>>B                    1
>>B                    2
>>B                    3
>>So, that's what this function is supposed to do.  I'm having a problem
with
>>the computer{*filter*} after 4-5 iterations through the loop.  The following
>>code is the while loop that is causing problems.  Does anyone see a
problem
>>here:  Thanks for any help!!!
>>      while(i <= 10)
>>      {
>>         if (FirstRec == NULL)
>>         {
>>            FirstRec = malloc( sizeof( struct rLabel ) + 1 );
>>            NextRec = FirstRec;
>>            sprintf(tempPoint, "%s", f4str(f4BPoint));
>>            sprintf(NextRec -> bPoint, "%s", tempPoint + 4);
>>            sprintf(NextRec -> pLabel, "%s", f4str(f4PLabel));
>>            NextRec -> Next = NULL;
>>         }
>>         else
>>         {
>>            NextRec -> Next = malloc( sizeof( struct rLabel ) + 1 );
>>            NextRec = NextRec -> Next;
>>            sprintf(tempPoint, "%s", f4str(f4BPoint));
>>            sprintf(NextRec -> bPoint, "%s", tempPoint + 4);
>>            sprintf(NextRec -> pLabel, "%s", f4str(f4PLabel));
>>            NextRec -> Next = NULL;
>>         }
>>         dbNext(d4Labels);
>>         strncpy(tempType, f4str(f4BPoint), 4);
>>         tempType[4] = '\0';
>>       i++;
>>      }



Tue, 19 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Computer hangs in loop

2. Computer hangs in while loop

3. revisit Hang computer prog.

4. Computer Hang Up Prog.

5. wihle loop with continue --> thread hangs

6. Debugging tmer loop WIndows HUng problem

7. Timer loop hangs WIndows

8. Sending Screen from computer to computer

9. About dialing from one computer to another computer

10. For loops into for loops

11. Loop or Loops in "C"

12. (Newbie) My Loop Isn't Looping - Aargh!

 

 
Powered by phpBB® Forum Software