Author
Topic: Very Very Simple C Question (Read 5168 times)

I figure at the very least paulscode and Egon will know: what does the line "typedef struct animation Animation" do in a header file? I see no other defining reference to animation (lower or upper case) anywhere in this little assignment. I haven't done C programming in so long, I forgot more than I knew I had known. And to clarify, the assignment uses Animation* pointers a lot, I meant that this line is the only part that defines it.

typedef struct data{ int x; int y;} Data;Data d;So for your example, it looks like the developer has created a data type he wants to reference as "Animation" rather than "struct animation" (i.e. less typing).

Ah, ok I see that now (I was looking at the return &a part which is correct). Would it be possible to change the animation struct so that the "title" there is a pointer instead of an array. That way, you would allocate memory outside the struct and simply pass it a pointer.

Of course there is a way to use what you have now (i.e. reading chars from the pointer and placing them into the array), but it seems to have slipped my mind at the moment (I've been playing with Java too much lately, I guess).

Same here, pal! Java and C# rot our brains. : -) But no, unfortunately I have to use what I have. It's an assignment, and not even mine at that, but I'm trying to re-learn this so I can pass it on to my friend.

Man, C can be so weird! It now compiles, except for the fact that it tells me that I'm returning the address of a local variable (so I just put it outside the function but I wanted to mention it anyway). Thanks again, pal.

Oh, and while (cursor->next != NULL) is giving me a "NULL undeclared; first use in this function" message (same for lower-case). So what's the C equivalent? I think I do remember testing for 0 or something but a quick Google seems to have suggested I could use NULL. But gcc won't take it, so what's the equivalent?

In this case, you are reading the first character of a string pointed to by a char*, and comparing that char to the length of the string. The problem is probably related to type-casting, comparing a char to an int, or something along those lines (I'm actually surprised this compiles). However, I assume that is not what you are trying to do here. What do you want to figure out with this if statement?

I thought this represented the index in the char array, or why would *cursor->canvas++ be possible? It must then be the char, and the compiler treats *cursor->canvas++ as a shortcut to increasing the index. What I needed ws to tell it not to go outside the bounds of the string, so I changed the code to keep track via a separate int.

EDIT: But the source of the crash had actually been strlen itself, since the string for a reason I hadn't seen was NULL.