1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void fonction (char* from, char* dest);
int main()
{
char Depart[7]="azerty";
char Copie[3][3];
char* tmp; size_t count;
fonction(Depart, (char*) Copie /*or *Copie*/);
for (tmp=(char*) Copie /*or tmp=*Copie*/, count=0; count < 3; ++count, tmp+=3) {
printf("%s\n", tmp);
}
return EXIT_SUCCESS;
}
// dest should be either char[3][3] or char[9]
void fonction (char* from, char* dest)
{
memset(dest, '\0', 9);
while((*from) != '\0') {
(*dest) = (*from); ++dest; ++from;
if ((*from) != '\0') { (*dest) = (*from); dest += 2; ++from; }
}
// or
// do {
// if ((*from) != '\0') { (*dest) = (*from); ++dest; ++from; }
// if ((*from) != '\0') { (*dest) = (*from); dest += 2; ++from; }
// } while((*from) != '\0');
} |