|
-
June 30th, 2004, 07:14 AM
#1
Doubt in malloc()
Hi,
I have a doubt while specifying the size in malloc().
int main()
{
char *str;
str = (char *)malloc(sizeof(char) * 256);
scanf("%s", str);
}
the above program will work fine, only if the inputed strings length is less than 256. Is there anything available, which can calculate the size dynamically?
so that irrespective of the length of the inputed string, my program should work fine.
regards,
Ashok
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|