Re: I cant do change string to int.



In article <1194796010.099997.68670@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, emre
esirik(hacettepe computer science and engineering)
<emreesirik@xxxxxxxxx> wrote on Sunday 11 Nov 2007 9:16 pm:

char poli[50];
int p;
scanf("%s", poli);
if(poli[i]=='X' && poli[i+1]=='^')
{
toplam=i+3;
p=poli[i+2];

p is a ASCII code of integer but I need integer
for example if poli[i+2]='2' it puts p 50 (ascii code of '2')
but I need p=2 integer form, how can I do, please help

Do:

p = poli[i+2] - '0';

This only works for '0'... '9'.

.



Relevant Pages

  • I cant do change string to int.
    ... scanf("%s", poli); ... p is a ASCII code of integer but I need integer ... but I need p=2 integer form, how can I do, please help ...
    (comp.lang.c)
  • Re: I cant do change string to int.
    ... int i,d,l,toplam,polinom; ... scanfexceed the bounds of 'poli' and overwrite memory it ... Note that 'sizeof poli' only works as expected within the function ... Because 'z' is always zero. ...
    (comp.lang.c)
  • Re: I cant do change string to int.
    ... int i,d,l,toplam,polinom; ... scanfexceed the bounds of 'poli' and overwrite memory it ... Note that 'sizeof poli' only works as expected within the function ... Note also that scanf and fgets return values which should be checked, otherwise you won't know if you actually received *any* input. ...
    (comp.lang.c)
  • Re: greatest of two numbers
    ... Your entire attempt is stupid, ... int get_max ... what will be used in the real engineering environment. ... programming language C rather than the compiler generated assembly. ...
    (comp.lang.c)
  • Re: greatest of two numbers
    ... Your entire attempt is stupid, ... int get_max ... what will be used in the real engineering environment. ... programming language C rather than the compiler generated assembly. ...
    (comp.lang.c)