Help with scanf and arrays - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with scanf and arrays

KotikKotik Posts: 7Member
I am currently learning C and have come across an issue I cannot find an answer anywhere. Basically I want an input of 10 digits (all in one singular input) and scan each number into an array.

Let me clarify a little more with the code:
#define N 10

int main(void)
int i, a[10];
printf("Please enter the 10 digits (sith spaces in between) (Y Y M M D D X X X X) : ");
for (i=0; i<N; i++)
scanf("%1d", a[i]);
printf("%d", a[3]);
return 0;

Basically I want the user to input 10 digits and then have those numbers scanned into an array. I don't want to do it the easy way of having the user type 1 digit at a time followed by hitting the enter key every time.

However this code of mine gives a "segmentation fault." So I assume I'm doing something wrong.

Any help appreciated!


Sign In or Register to comment.