Jump to content
bogdanvaduva

Transform a string into a 32-bit number

Recommended Posts

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...