isbn problem (barcodes on books)

• 10-16-2002
djxtremor
isbn problem (barcodes on books)
does anyone know how i can be able to do operations on individual characters from a users input ??

lets say user typed in : 0-8797-0658-9

(isbn problem)
i want to multiply 8 with 2, 7 with 3, 9 with 4, and so on ..
can anyone help me out get those individual numbers from the string so i can do some operations?? thanx
• 10-16-2002
Dave_Sinkula
Quote:

Originally posted by djxtremor
does anyone know how i can be able to do operations on individual characters from a users input ??

lets say user typed in : 0-8797-0658-9

(isbn problem)
i want to multiply 8 with 2, 7 with 3, 9 with 4, and so on ..
can anyone help me out get those individual numbers from the string so i can do some operations?? thanx
Another idea:
Code:

```#include <stdlib.h> #include <stdio.h> #include <string.h> void f1(const char *buff) {   int result;   char s[5] = {0};   strncpy(s, &buff[2], 4);          /* copy the second field to s[] */   result = (int)strtol(s, NULL, 10); /* convert s[] text to int */   printf("result = %d\n", result);   strncpy(s, &buff[7], 4);          /* copy the third field to s[] */   result = (int)strtol(s, NULL, 10); /* convert s[] text to int */   printf("result = %d\n", result); } int main(void) {   const char isbn[] = "0-8797-0658-9";   f1(isbn);   return(0); } /* my output result = 8797 result = 658 */```
• 10-16-2002
quzah
Quote:

Another idea:
This doesn't do what the original poster wants. They want this basic formulae:

string[x] * n;

Where n increments once with each place in.

Thus, if our string were:

1357

It would do:

value = 1 * 2
value = 3 * 3
value = 5 * 4
value = 7 * 5

Where 'value' is the resulting value of the multiplication operation for that cell in the array / string.
Where the value you're multiplying by increments once for each place further along in the string.

So in essence it simply boils down do:

x = 0, n = 2;
string[x++] * n++;

Your example just turns the string form of the number into its literal integral value. As usual, Salem's answer was what they were looking for.

Quzah.
• 10-16-2002
djxtremor
thanx for the help guys ..sorry bout that salem .. i thought both of them were the same thing (buff[i] *2 = ((buff[i] -'0') *2).. but i tried your suggestion and it worked .. thanx so much ..