c - How do I increment pointer in stringtable? -
I am filling a stringbabelsible four * data [500] with the pointer for different stars.
four * data [500]; Int stringC = 0; Four printbuffers [200]; Zero data_desplay (zero); Zero print string tab (zero); Int main () {data_display (); // Fill buffer printstringtable (); Return 0; }
Here I use another buffer so that I can store an index in the string:
zero data_display (zero) {int index = 0; Sprintf (printbuffer, "a text% d \ n", index); Output (PrintBuffer); Index ++; Sprintf (printbuffer, "b text% d \ n", index); Output (PrintBuffer); Index ++; Sprintf (printbuffer, "C text% d \ n", index); Output (PrintBuffer); }
While debugging, I can see that the indicator always indicates the same address.
Zero Output (Four * Buffer) {Data [String C] = Buffer; Four * (* PTR) [500] = More data; String C ++; Ptr + = stringC; } Zero printStringTable () {int i; For (i = 0; i If I have another string using a buffer (printbuffer) without a separate address and I am getting it:
A lesson b text 1c <2 p>
But in this constellation I get:
C text 2C text 2C text 2
Is it a way to increase the indicator so that it is a Indicates at a different address? Point to all points of the head point is the same place,
data Which is
PrintBuffer
.
You have to allocate a new buffer for each of your strings.
Output function shoukd can be modified like this:
zero output (four * buffer) {char * newbuffer = strdup (buffer); Data [stringC] = newbuffer; // Deleted: It is unusable four * (* ptr) [500] = & amp; Data; String C ++; // Removed: this is a worthless PTR + = string C; }
Comments
Post a Comment