Jump to content

Conversão de string para int incorrecta


jpedro7

Recommended Posts

Quando converto duas strings para inteiros o resultado aparece errado porquê ?

código:

int i, x, a=0, c, d;
char var_i[2], var_f[2];

printf("\nQual a 1ª linha a eliminar exemplo(1) \n");
scanf ("%s", &var_i);
printf("\nQual a ultima linha a eliminar exemplo(2)\n");
scanf ("%s", &var_f);

c = atoi(var_i);
d = atoi(var_f);
printf("prim...%d \n", &c);
printf("seg...%d \n", &d);

No teste preenchi no primeiro printf coloquei  o valor 2 e no segundo printf também o valor 2 e o resultado foi este:

        prim...1244204   

        seg...1244192

Alguem me pode ajudar ?

Obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.