I am trying to use the take input from a user and store the informatin that is input on the heap. I am close.. (i think) but keep getting errors. The problem occurs when the user chooses option #3 and begins to input data.
My files are attached.
Printable View
I am trying to use the take input from a user and store the informatin that is input on the heap. I am close.. (i think) but keep getting errors. The problem occurs when the user chooses option #3 and begins to input data.
My files are attached.
OK i though my files were attached.. here they are
>>if(len = strlen(p->name) > NAME_SZ)
How many equals signs needed to make a comparison?
>>char *filename;
>>scanf("%s", filename);
filename is a pointer, not an array. I'd suggest:
>>char filename[BUFSIZ];
In main():
>>if(size >= MAX)
What value does size have when you invoke this line of code? Think about it.... ;)
There are more things too, see how you get on....
If you want dynamic allocation, try:
I've heard bad things about 'scanf()', the second line of code above will at least solve running into the end of an array.Code:char *filename;
filename = malloc(100);
scanf("%s", filename);
{edit}
1) You're dereferencing filename, and are trying to assign the return of malloc there. That's wrong. Lose the first *. Because you're making an assignment to a pointer, not to what it dereferences to.Quote:
Originally Posted by loopy
2) This eliminates running off the end of an array, true. But you can still blow by the end of your malloced memory. All I have to do is enter 101 characters without any white space and I've gone off the end.
The FAQ covers safer ways of getting input if anyone's interested.
Quzah.
Thanks, I've edited it. :)Quote:
Originally Posted by quzah