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
*/