c - issues with printing messages after collecting them using sprintf -


i have example code in trying collect messages in buffer (torprint) , print messages on screen after collection. once printed want clear buffer , start storing new messages again in same buffer.

the end use case idea print on demand printing right after collect proof of concept

#include <stdio.h>  int i,j; char torprint[100]; char* pos=torprint; char* fp=torprint; int main() {     for(j=0;j<4;j++)    {         (i=j;i<8;i++)         {             pos += sprintf(pos, "data entry number : %d\n",i);         }         printf("%s\n",torprint);         pos=fp;    }    return 0; } 

this compiles , runs noticed loosing new data on course. can 1 me figure out doing wrong???

output above code:

data entry number : 0 data entry number : 1 data entry number : 2 data entry number : 3 data entry number : 4 data entry number : 5 data entry number : 6 data entry number : 7  data entry number : 1 data entry number : 2 data entry number : 3 data entry number : 4 data entry number : 5 data entry number : 6 data entry number : 7  data entry number : 2 data entry number : 3 data entry number : 4 data entry number : 5 data entry number : 6 data entry number : 7  data entry number : 3 data entry number : 4 data entry number : 5 data entry number : 6 data entry number : 7 

thanks


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -