jeudi 21 février 2019

While loop stuck after processing last line of array in C

Hi all below is my code which gets stuck at "if((p_note_for_sm[msg_line_no]) != NULL)" in function "int Ms_SEnd(char **p_note_for_sm)" , After debugging the if condition i found that the value of p_note_for_sm[msg_line_no] is not getting printed after processing upto last character of array and program unable to break from while loop and program gets stuck . (i expect the value NULL in (p_note_for_sm[msg_line_no]) to break this loop ) , Kindly help me to find out the solution.

    #include <stdio.h>
    #include <string.h>
    #include <strings.h>
    #include <stdlib.h>
    #include <math.h>
    #define SMAXLINE              200

    int Ms_SEnd(char **p_note_for_sm)
    {
        int msg_line_no=0;

            while(msg_line_no <= 200)
       {
        if((p_note_for_sm[msg_line_no]) != NULL)
            {
              if(strcmp(p_note_for_sm[msg_line_no],"\0") != 0)
              {
                  printf("\nMsg In SM loop inside [%s]",p_note_for_sm[msg_line_no]);    
              }
             else
             {
                 break;
              }
           msg_line_no++;
        }
        else
            {
             break;
             }
       }
    }
    int main()
    {
        char *chr_h_note_for_sm[SMAXLINE] ;
        char chr_h_note_1_new[8000]="\0";
        char chr_h_note_new[8000]="1 RECITE PREVIOUS MINUTES OF LAST AGM  2 DISCUSS THE BOD REPORT  3 DISCUSS THE AUDITORS REPORT  4 DISCUSS THE GENERAL BUDGET WITH THE PROFIT AND LOSS AND DISCUSS THE PERCENTAGE OF  CASH DIVIDENDS THAT WILL BE DISTRIBUTED  5 INDEMNIFY THE BOD  6 ELECT THE AUDITORS FOR THE YEAR 2019  7 DISCUSS OTHER ISSUES";
        int l_tail_pos = 0;
        int l_counter = 0;
        int msg_line_no=0;
        int rownum=1;
        int l_temp = 0;
        int l_length = 305;
        while(l_tail_pos < l_length)
        {
            chr_h_note_for_sm[l_counter]=(char *)calloc(36,sizeof(char));

            if((l_length - l_tail_pos) < 35)
            {
                for(l_temp=0;l_length>l_tail_pos;l_temp++)
                {
                    chr_h_note_for_sm[l_counter][l_temp]=chr_h_note_new[l_tail_pos++];
                }
                    chr_h_note_for_sm[l_counter][l_temp]='\0';
            }
            else
            {
strncpy(chr_h_note_for_sm[l_counter],chr_h_note_new+l_tail_pos,35);
                chr_h_note_for_sm[l_counter][36]='\0';
            }
          l_counter++;
          l_tail_pos = l_tail_pos +35;
        }

        Ms_SEnd(&chr_h_note_for_sm);
        return 0;
    }

Aucun commentaire:

Enregistrer un commentaire