bogdanvaduva Posted April 29, 2016 Report Posted April 29, 2016 Salut, Am intalnit urmatoarea problema. Primesc un char * care reprezinta un ip. Ideea e ca eu trebuie sa compar mai multe ip-uri, dar, trebuie ca ele sa fie transformate in int32_t, adica numere pe 32 de biti. Are cineva idee cum se face asta? Initial am incercat ceva de genul asta #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> int main (){ char * buffer; int sum = 0, i; buffer = (char*)malloc(100*sizeof(char)); scanf("%s", buffer); int32_t x; x = (int32_t)buffer; printf("%zu\n", x); } Am mai incercat la afisare sa fac cu %lo dar nu am obtinut nimic. Are cineva idee :D? Quote
kznamst Posted April 29, 2016 Report Posted April 29, 2016 (edited) http://stackoverflow.com/questions/8167257/right-way-to-convert-char-number-to-int32-t <inttypes.h> int32_t i; sscanf(str, "%"SCNd32, &i); Edited April 29, 2016 by kznamst Quote
Byte-ul Posted April 29, 2016 Report Posted April 29, 2016 http://stackoverflow.com/questions/10283703/conversion-of-ip-address-to-integer Quote