mercredi 8 février 2017

why strncpy with for loop array pointer keep running forever

Vote count: 0

I have variable as

char buff[10] = "000000000";
char data01[4] = "abc"; char data02[4] = "def";

and I want to using strncpy to have buff[10] = abc00def0

so I try

    int i = 0;
//abc00def0
for(; i < 3 ; i++){
    strncpy(&(buff[i]), &(data01[i]),i);
 //   printf("test %d\n",&(data01[i]));

}
i = 5;
for( ; i < 8 ; i++ ){
      strncpy(&(buff[i]), &(data02[(i-5)]),i);
}

 printArray(buff,sizeof(buff));

but when I try to run the code is running forever. Thank you very much

asked 20 secs ago

Let's block ads! (Why?)



why strncpy with for loop array pointer keep running forever

Aucun commentaire:

Enregistrer un commentaire