1. ## array help

ok i need to write a programme that asks the user to input student numbers as an array and check the initial number and allocate them into different classrooms.. my code looks lik ths:

#include <stdio.h>

int number;
int i;
int student_number[10];
int total;
int first[0];

int main (void)
{

printf("Enter the total number of students ");
scanf("%d", &total);

for (i=1; i<=total; i++)
{
printf("Enter the student number\n: ");
scanf("%d", &student_number);
printf("first digit is %d\n", student_number[0]);

if (student_number[0] < 5)
{
printf(" Classroom A\n");
}
else if (student_number[0] >5)
{
printf(" Classroom B\n");
}

}

system ("pause");
return 0;
}

the code only works if there is a space between the digits, ie. if input is 23 3, i get the first digit as 23. what should i do so that it extracts the first digit from the number with no spaces in between?

2. Code:
```int a, b;
scanf("%1d%1d",&a,&b);```
%1d puts a single digit in.

You may want to read this, btw:

STDIN pitfalls

3. thanks but is there a way i can pass it into an array and extract the first digit only?

4. Originally Posted by ancientdragon
thanks but is there a way i can pass it into an array and extract the first digit only?
Code:
```int array[10], i;
for (i=0; i<10; i++) scanf("%1d",&array[i]);```
So if you type:
9413823144
each digit will be a separate element in the array.

5. Originally Posted by ancientdragon
thanks but is there a way i can pass it into an array and extract the first digit only?
Read it as a string, compare the spot you want with isdigit.

Quzah.