Can a scanf function see a number input "1234" as 4 separate numbers?
I am doing an ISBN digit check program. I'm not actually in school, but it's on the curriculum in a lot of C classes. Naturally want to be able to do it.
I am trying to figure it all out, having tried twice and failed. My biggest hurdle/question is:
Can you have a "scanf" function that sees the user input/ISBN like this: 1234567890.
With no spaces or dashes, and have the program not treat the ISBN input as one number? Have the program understand that it should take each digit and place each one in a slot on an array? So, using the above number, it would get: isbn[0] = 1, isbn[1] = 2, etc.
I have no program to show because I have scrapped them all, seeing as how i was going about it in completely the wrong way. I want to start fresh with new knowledge.
Simply the simplest solution
First remember my friend its about algorithm and not the syntax of the language
Here is a standalone program run it to understand what is my solution
I printed every number-every entry of the array on a new line to prove my point
you have to edit it to match your needs , but the key idea is here
Code:
#include<stdio.h>
#include<string.h>
void isbn();
main()
{
isbn();
}
void isbn()
{
int length;
int i=0;
char isbn[10]={'\0'};
int i_isbn[10];
printf("Enter ISBN ");
scanf("%s", isbn);
length=strlen(isbn);
for(i==0; i<length; i++)
{
i_isbn[i]=(((int)isbn[i])-48);
printf("\n%d", i_isbn[i]);
}
}