A
Anitha Adusumilli
Hi
I am getting bus error, if I include the line "free(stra)" , in the
following code:
#include <stdio.h>
char *func(int);
int main(void)
{
int i;
printf("enter the integer\n");
int num_Args=scanf("%d", &i);
if(num_Args<1)
{
printf("Not a valid number of inputs");
exit(1);
}
char *stra= func(i);
printf("\nprinting the string %s\n",temp);
if(stra!=NULL)
free(stra);
return 0;
}
I have another function "func" which returns the result as a char*. I
used malloc to assign memory to this char* in "func".
I amnt able to understand why this is happening..everything seems to be
fine..The output is also as expected.But still, I amnt able to free the
char*.
Am I missing any pt?
Regards
Anitha
I am getting bus error, if I include the line "free(stra)" , in the
following code:
#include <stdio.h>
char *func(int);
int main(void)
{
int i;
printf("enter the integer\n");
int num_Args=scanf("%d", &i);
if(num_Args<1)
{
printf("Not a valid number of inputs");
exit(1);
}
char *stra= func(i);
printf("\nprinting the string %s\n",temp);
if(stra!=NULL)
free(stra);
return 0;
}
I have another function "func" which returns the result as a char*. I
used malloc to assign memory to this char* in "func".
I amnt able to understand why this is happening..everything seems to be
fine..The output is also as expected.But still, I amnt able to free the
char*.
Am I missing any pt?
Regards
Anitha