![]() |
Hm, I think, what it's wrong, I patched that, but I've got there...
Code:
for (i = 0; i < 4; i++) |
Quote:
That achieves the concatenation without needing either strcat or separate buffer (such as the buffer inside itoa in my earlier example) Quote:
So inside the loop you see only each chunk one at a time and outside the loop you see only the last chunk. If you have the concatenation working then inside the loop you would see each everything up to and including the current chunk and outside the loop, you would see the whole thing. |
sprintf(p->adr + strlen(p->adr),
it's doesn't work. because it doing sumup value, when it doing via sprintf. Furthermore, on result I've got wrong value in p->adr But, I not understand why printf into cycle is working, but outside "for()" it does not. for(){ ... printf("%s\n", p->adr); //good 10.10.10.3 } printf("%s\n", p->adr); // is not good 0.0.0.3 |
Quote:
But this time I'll guess: dwhitney67 allocated the structure using struct data *p = calloc(1, sizeof(struct data)); That zeroes the entire structure when allocated, so you don't need to null terminate the buffer. You may have allocated the structure some other way. Some methods of allocating the structure would require that you null terminate the string before using strlen(p->adr). This should be done once, after allocating the struct and before starting the loop. either p->adr[0] = 0; or p->adr[0] = '\0'; are equally valid. |
Quote:
which's way I can take successful useful printf outside this loop? Hm, I think what if I'll tried usage construction strca and itoa it's not change result of printf outside of the loop. |
quannt -
What part of the code that I posted earlier do you not understand? |
All times are GMT -5. The time now is 05:37 AM. |