Hello,...
i got a strange beahvioer with NULL and 0 (when working on SMSer progect source attached):
This code will work fine for me :
Code:
int CalcPendingSMS()
{
FILE *fp = NULL;
char tmp[MAXLINELENGTH];
int counter=0; //array counter
//add home path to centericq
char OfflinePath[MAXLINELENGTH];
sprintf(OfflinePath,"%s%s", HOMEDIR,OFFLINEFILE);
fp=fopen(OfflinePath,"r");
printf("%d",fp);
if (!fp)
{
return -1;
}
while (fgets(tmp,MAXLINELENGTH,fp)!=NULL)
counter++;
fclose(fp);
counter=(counter) /7;
return counter;
}
but this won't (SIGSEGV error )
Code:
int CalcPendingSMS()
{
FILE *fp = NULL;
char tmp[MAXLINELENGTH];
int counter=0; //array counter
//add home path to centericq
char OfflinePath[MAXLINELENGTH];
sprintf(OfflinePath,"%s%s", HOMEDIR,OFFLINEFILE);
fp=fopen(OfflinePath,"r");
printf("%d",fp);
if (fp == NULL)
{
return -1;
}
while (fgets(tmp,MAXLINELENGTH,fp)!=NULL)
counter++;
fclose(fp);
counter=(counter) /7;
return counter;
}
but the problem is that afaik there isn't any real difference between that two.