Re: I cant do change string to int.



emre esirik(hacettepe computer science and engineering) wrote:

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

/Please/ don't offer us random fragments of code; offer us
complete (but small) compilable (unless of course your problem
is a compilation problem) programs. For example, the fragment
above doesn't have a declaration for `i` in it: what /else/
has been missed out?

Are you /sure/ you want to be using `scanf` here, rather than
`fgets`?

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

To convert a digit character into the corresponding value, you
simply subtract `'0'`, eg

int seven = '7' - '0';

C specifies that the digit characters are in order without gaps
(whereas it does /not/ do this for letters).

--
Non-Digital Hedgehog
"The path to the web becomes deeper and wider" - October Project

.



Relevant Pages

  • Re: bind8.2.3 port
    ... > But I think there is a compilation problem with it.I ... > am not sure but I have tried to compile that port 4 ... Sounds like a hardware or general system problem. ...
    (FreeBSD-Security)
  • compile problem in Mac Os X 10.5.7
    ... I have the following compilation problem, I think I am missing something very simple, it would really be nice if some of you could point it out to me. ... Should I do some additional setup for the Xcode Tools? ...
    (comp.soft-sys.matlab)
  • Complation problem involving namespaces.
    ... Hey all I have a little compilation problem I think is related to name ... I am attempting to link a C lib and I think the complication comes in here ...
    (comp.lang.cpp)