L
Lampa Dario
Hi,
I need to estract single characters in a string, that may be '0' or '1',
and evaluate them.
I defined these variables
char *binary;
char cypher;
int value;
then
binary=malloc(32);
scanf("%s",binary);
n=strlen(binary);
If I write
for (i=0;i<n;i++)
{
strcpy(cipher,binary);
value=atoi(cipher);
....
}
I get a compilation error.
If I write
cypher=atoi(binary);
I get another compilation error .
What is the correct procedure to evaluate every single char in a string?
At the end I wrote
value=binary-'0'
and everything worked fine.
Francesco
What I need is to evaluate all the 0s and 1s in the string
I need to estract single characters in a string, that may be '0' or '1',
and evaluate them.
I defined these variables
char *binary;
char cypher;
int value;
then
binary=malloc(32);
scanf("%s",binary);
n=strlen(binary);
If I write
for (i=0;i<n;i++)
{
strcpy(cipher,binary);
value=atoi(cipher);
....
}
I get a compilation error.
If I write
cypher=atoi(binary);
I get another compilation error .
What is the correct procedure to evaluate every single char in a string?
At the end I wrote
value=binary-'0'
and everything worked fine.
Francesco
What I need is to evaluate all the 0s and 1s in the string