1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <string.h>
#include <stdio.h>
int main(void)
{
const char* ip = "10001101000110111000110010001101"; // notez lutilisation de const
char part1[9] = {0};
char part2[9] = {0};
char part3[9] = {0};
char part4[9] = {0}; // 9 = 8 caractères utiles + 1 caractère terminal ('0' == 0)
strncpy(part1, ip, 8);
strncpy(part2, ip + 8, 8);
strncpy(part3, ip + 16, 8);
strncpy(part4, ip + 24, 8); // ça fait beaucoup de 8... On pourrait de créer une constante avec #define
puts(ip);
puts(part1);
puts(part2);
puts(part3);
puts(part4);
} |