I quickly looked at your 'addMyString' function...Your adding the character before you check the capacity. Shouldn't it be the other way around?
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
I see quite a few issues, but the most immediate is a misunderstanding of how pointers work when passed to a function. Your initMyString will completely fail to do what you're expecting because the parameter is a copy of the argument, not a reference to it.
See this article for more details. Fix that and we can talk about further issues. ;)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>but if you're passing in the address of a pointer, how is that a copy of the pointer?
Pointers aren't magic. A pointer is just a variable, and the value of that variable is an address. You wouldn't expect the following to print 12345, would you? The idea is exactly the same:
#include <stdio.h>
void foo(int x)
{
x = 12345;
}
int main(void)
{
int x = 0;
foo(x);
printf("%d\n", x);
return 0;
}
Adding a level of indirection seems to make people forget the most fundamental concepts of C.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>if I'm required to pass in a pointer I don't see how I can pass in a pointer to a pointer
If you're being passed a pointer, simply assume that it already points to a valid object. You don't need to call malloc on aStr, but you do need to malloc aStr->data .>Unfortunately I can't find any examples of how ADT's work so obviously I have no idea what I'm doing.
You can find several ADT examples in the libraries section here . They're serious libraries though, not student examples, so they may or may not be helpful.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401