A bit of an issue, converting char into int...
Hello you wonderful people...
I was wondering if I could get your help real quick please, and thank you...
So I want to write a code for an assignment to validate an ISBN number.
So once the user inputs the number, I need to take each digit and multiply it by a predetermined weight, but since I am using a string array for the input, I am having a bit of a problem. The program runs, but gives me the wrong results...
Can you please help me to figure out how to convert a char into int. I have used atoi, but that converts the entire input rather than digit by digit.
Thanks a bunch
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main(void)
{
char isbn[80];
int len, n, weight ;
int weighted_value;
int counter=0;
printf("please enter the ISBN number: ");
scanf("%s", isbn);
printf("the first number is %c\n", isbn[0]);
printf("the second number is %c\n", isbn[1]);
printf("the third number is %c\n", isbn[2]);
printf("the fourth number is %c\n", isbn[3]);
printf("the fifth number is %c\n", isbn[4]);
printf("the sixth number is %c\n", isbn[5]);
printf("the seventh number is %c\n", isbn[6]);
printf("the eighth number is %c\n", isbn[7]);
printf("the nineth number is %c\n", isbn[8]);
printf("the tenth number is %c\n", isbn[9]);
len = strlen(isbn);
if (len <= 10)
{
printf("valid\n");
//while (counter!=10)
//{
weight = 10;
//HERE IS WHERE I NEED THE HELP, THANKS//
n=atoi(isbn[0]);
weighted_value=n*weight;
printf("the n value for the first number is %d\n", n);
printf("the weighted value for the first number is %d\n", weighted_value);
//}
}
}