Conversion of string to integer array?
Hi.
I'm trying to make a program that reads an input of a barcode number, then validates the "check digit" (the last digit) with an algorithm. I am stuck at the start. In order for the algorithm to work, the barcode must be in separate digits, not a 'number' so to speak.
I need the input to be a char string because it may start with '0', which wouldn't count if it were an integer.
Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#define SIZE 12
int main() {
char str[SIZE];
int digit[SIZE];
int i;
fgets(str, 14, stdin);
for(i = 0; i < 12; i++){
str[i] = digit[i];
}
system("pause");
return 0;
}
I know this is completely wrong, but it is all I have so far. I'm not worried about the algorithm or output, just the conversion of the string of numbers into an integer array.