0

I know its probably obvious issue but since in very new to C I had to ask,

This is my code:

#include <stdio.h>
#define ASIZE 8
int main()

{
    int index;

    long int numbers[ASIZE];

    printf("enter 8 integers to be printed in reverse order:\n");

    for (index = 0; index < ASIZE; index++)

    {
        scanf("%li", &numbers[index]);
    }

    printf("indexing is done!");

}

Why am I not exiting the 'for' loop and printing "indexing is done!" ?

7
  • sorry the ASIZE is defined @Oli Charlesworth
    – JohnBigs
    Jan 24, 2013 at 19:23
  • just edited, its the size limit for the array @user droog
    – JohnBigs
    Jan 24, 2013 at 19:24
  • 1
    What are you typing as input when you run your program? If it isn't 1 <enter> 2 <enter> 3 <enter> 4 <enter> 5 <enter> 6 <enter> 7 <enter> 8 <enter>? Jan 24, 2013 at 19:25
  • im typing 8 integers together..shouldn't in able to do that? only enter? @RichieHindle
    – JohnBigs
    Jan 24, 2013 at 19:26
  • 3
    What do you mean 'together'? Like 12345678? That's just one integer. Spaces will work for your program too.
    – Carl Norum
    Jan 24, 2013 at 19:27

3 Answers 3

1

scanf requires your inputs to be whitespace-separated. Entering 12345678 will only go once round the loop.

0
1

This will/should work provided that you have entered space, enter, tab separated inputs. If you are entering e.g. 82341679 as 8 numbers, these are not eight inputs, this is just only one input.

0
1

You are really new to C ! Anyways, just to make things clear, your code is perfectly fine. Input the numbers like 1 2 3 4 5 6 7 8

and not like 12345678, since it itself is one integer. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.