Hi guys,
I am trying to create to parse the content of a char array into integer as follows but I cant do it and keep getting the following error. Any solution or suggestion is welcome.
*************** *************** *************
#include <stdio.h>
#include <ctype.h>
int main()
{
char isbn[20];
int weight[10] = {10,9,8,7,6,5,4 ,3,2,1};
int numericisbn[20];
int product;
int sum = 0;
printf("Enter your ISBN number: ");
fgets(isbn, 20, stdin);
int i;
for (i = 0; i < strlen(isbn); i++)
{
numericisbn[i] = atoi(isbn[i]);
}
printf("%d\n", numericisbn[0]);
printf("%d\n", numericisbn[1]);
printf("%d\n", numericisbn[3]);
}
*************** *************** *************
The code compiles and the error message I get is:
Segmentation fault(core dumped)
Any help or suggestion is appreciated.
I am trying to create to parse the content of a char array into integer as follows but I cant do it and keep getting the following error. Any solution or suggestion is welcome.
*************** *************** *************
#include <stdio.h>
#include <ctype.h>
int main()
{
char isbn[20];
int weight[10] = {10,9,8,7,6,5,4 ,3,2,1};
int numericisbn[20];
int product;
int sum = 0;
printf("Enter your ISBN number: ");
fgets(isbn, 20, stdin);
int i;
for (i = 0; i < strlen(isbn); i++)
{
numericisbn[i] = atoi(isbn[i]);
}
printf("%d\n", numericisbn[0]);
printf("%d\n", numericisbn[1]);
printf("%d\n", numericisbn[3]);
}
*************** *************** *************
The code compiles and the error message I get is:
Segmentation fault(core dumped)
Any help or suggestion is appreciated.
Comment