My Code won't exit

This is a discussion on My Code won't exit within the C Programming forums, part of the General Programming Boards category; This function only runs during a hardware interrupt generated by the UART. I use the Borland 'interrupt' function. The interrupt ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Angry My Code won't exit

    This function only runs during a hardware interrupt generated by the UART.
    I use the Borland 'interrupt' function. The interrupt function then calls this 'sub function'...
    The function does it's operations correctly, but during this it won't exit my do-while loop -triggered by the Done flag. And i'm surtain that the string has reached it's size.

    If you need to see my interrupt function -i'll show you, but it's in this piece something goes wrong ;(


    void RunTest(void)
    {
    int y=2;
    unsigned char Done=0;
    DrawMenu();
    textbackground(CYAN);
    textcolor(BLUE);
    DrawBox(1,1,15,10);

    clrscr();
    printf("Tester...\n");
    printf("Debug lines only\n");
    do
    {
    if(serial.m_Bufferin !=serial.m_Bufferout)
    {
    serial.m_Buffer[serial.m_Bufferout]&=0x7f;
    serial.m_NewCharReceived=serial.m_Buffer[serial.m_Bufferout];
    serial.m_NewBarCode[serial.m_Index++]=serial.m_NewCharReceived;
    serial.m_Bufferout++;

    //printf("%c ->%d \n",serial.m_NewCharReceived,serial.m_Index);

    if(strlen(serial.m_NewBarCode)==11)
    {
    cputs(serial.m_NewBarCode);
    gotoxy(1,y++);
    dat.m_pCodes[dat.m_Count++]=strdup(serial.m_NewBarCode);
    serial.m_Index=0;

    Done=1;
    }
    }
    }while(!Done);

    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    reply

    Hmm, what is m_NewBarCode? A static array or a pointer? If it's a pointer, you must place a \0 (NULL terminating character) at the end of the string so strlen can calculate the length properly. And remember to allocate memory for it .

    serial.m_NewBarCode[serial.m_Index++]=serial.m_NewCharReceived;

    if(strlen(serial.m_NewBarCode)==11)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  2. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  3. Replies: 1
    Last Post: 03-21-2006, 06:52 AM
  4. how do you change the ctrl+C exit code?
    By Golden Bunny in forum Windows Programming
    Replies: 0
    Last Post: 04-09-2002, 02:18 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21