Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Iteration in C

Name: Anonymous 2010-06-14 3:53

Hi there /prog/.

I know Python, and I'm learning C. Both langs have for loops. Python's nicely iterates over a collection of unknown length. C's usually has you specify the length of the collection at compile time, but what if the length is unknown?

My best newbie guess: you terminate the collection with NULL, or you write an iteration function that returns some end-of-collection value when it's done.

Name: Anonymous 2010-06-15 18:30

>>60
Oh, sorry, I misread >>58. (>>59 was my first post in this thread, by the way.) You are indeed correct. But why do that anyway? This isn't Pascal.

But still, try this.
char *array = malloc (size + 4)
array += 4
#define LEN(a) (*(int*)(a)-4)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List