lundi 20 juin 2016

Cannot call a function inside a if loop

I'm just trying to call a function "char *get_time_clk()" inside a if loop. I'm working in PIC24F microcontroller. The issue is when i try to call inside if loop microcontroller restarts. If i call the function outside of the if loop its working. I can call other function except this.What could be the problem?

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 char *get_time_clk();
int main()
 { 
    init_processor();  //Initiate PIC
    Delayms(15000);
    printf("%s\n",get_time_clk());-----> **working here**
while(1)
    {
      if(http_conn)
                {
                   printf("%s\n",get_time_clk());------>**Not working**
                }
               .
               .
               .

    }
  return 0;
  }

char *get_time_clk()
  {
    int i,v=0,j=5,l=0,m=8,n=0,q=11,s=0;
    char yr[5],mm[5],dd[5],time[10],sp_chr[2]="-",date_fr[20];
    uart3str("AT+CCLK?\r");
    Delayms(500);
    int b,z=0;
    for(b=19;b<=35;b++)
     {
        cur_time[z]=gprs_buffer[b];
        z++;
     }
     cur_time[z]='\0';
     strcat(real_time,cur_time);
     for(i=0;i<=strlen(real_time);i++)
      {
        while(real_time[v]!='/')
         {
            yr[v]=real_time[v];
            v++;
         }

            while(real_time[j]!='/')
            {
                mm[l]=real_time[j];
                j++;
                l++;
            }

            while(real_time[m]!=',')
            {
                dd[n]=real_time[m];
                m++;
                n++;
            }

        }

        yr[v]='\0';
        mm[l]='\0';
        dd[n]='\0';
        time[s]='\0';
        int c,d=0,e=0;
        for(c=0;c<=strlen(real_time);c++)
        {
             c = c+11;e=c+8;
             do
                {
                    time[d] = real_time[c++];
                    d++;
                }while(c<=e);
            time[d] = '\0';
            c=200;
            c++;
        }
        snprintf( date_fr, sizeof(date_fr), "%s%s%s%s%s%s", yr, sp_chr, mm, sp_chr,dd," " );
        strcat(date_fr,time);
        return date_fr; 
        }

Aucun commentaire:

Enregistrer un commentaire