number biger then 9

M

Maq

What I must to change in:
#include <vector>
#include <_str.h>
#include <stdio.h>
#include <ctype.h>
void f_1(int a, int b)
{
printf ("f_1\n");
printf ("%d",b);
scanf ("%d",&a);
}
void main (int argc, char *argv[])
{
char buffor[512];
char *s1="b";
char *s2="a";
char c;
int a,x,h,b;
int i=0;
while((c=getchar()) != '\n')
buffor[i++]=c;
for(i=0;i<strlen(buffor);i++){
c=buffor;
if(isdigit(c)){
a=(c+0)-48;
for(x=i;x<strlen(buffor);x++){
c=buffor[x];
if(isdigit(c))
b=(c+0)-48;
}
i=x;
printf ("a-> %d\nb-> %d",a,b);
}
}
if(strstr(buffor,s1) && strstr(buffor,s2)){ f_1(a,b); }
}

to variable 'a' & 'b' was number biger then 9?
 
K

Karl Heinz Buchegger

Maq said:
to variable 'a' & 'b' was number biger then 9?

It is more then unclear what you are asking about.
But I take a guess:
You want to know how to convert a string containing
the character representation of a number, eg. "234"
to an int representing that number.

eg.

int number = 0;
char string = "234";
int i;

i = 0;
while( isdigit( string ) )
number = 10 * number + ( string - '0' );

That's just the same as you do it in real life:
You start reading from the left:

2 Oh yes, that's 2 for now, on to the next digit 2
3 That's a digit, so 'add' it to what there is already
You do this by multiplying by 10, thus makeing 20 out
of the 2 you already have, and add the 3
2 -> 20
+ 3
-------
23

So if the number would be finished, the 2 characters would
have formed the number 23

But on to the next digit

4 That's a digit. It is 'added' to what you have already in
very much the same way. Make 230 out of the 23 by mulitplying
with 10 and add the 4

23 -> 230
+ 4
----
234

On to the next digit

- There is no longer a digit. So the end result of converting
"234" into a number equals 234
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top