Thank you both. From what I gathered from you two, something like this should convert the digits.
Code:
#include <stdio.h>#include <string.h>
#include <stdlib.h>
#define SIZE 12
int main() {
char str[SIZE];
int digit[SIZE];
int i;
fgets(str, 14, stdin);
for(i=0; i<SIZE; i++){
str[i] - '0';
}
for(i = 0; i < 12; i++){
digit[i] = str[i];
}
printf("%d, %d, %d", digit[1],digit[2],digit[3]);
getch();
return 0;
}
the final printf outputs something like 50, 51, 52 every time?
I think I have a misunderstanding of strings, or atleast unknown strings which are obtained from input. I thought say,
Code:
char str[81];
printf("Enter a string: "); /*user enters "hello"*/
fgets(str, 81, stdin);
printf("%s", str[2]); /*output would be "l"*/
this would output "l" but it does not. what have I missed here?