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.
This is a discussion on Any Help Appreciated within the C Programming forums, part of the General Programming Boards category; I am trying to use the take input from a user and store the informatin that is input on the ...
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....
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
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}
Last edited by loopy; 05-04-2004 at 01:16 AM.
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.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.
Hope is the first step on the road to disappointment.