Reading numbers from console
Hi guys, I'm new to the forum.
I'm new to C and have only ever programmed in Java, therefore having a bit of problems at the moment.
I'm trying to write a program that reads ten numbers from the keyboard, stores
them in an array of integers and then prints out the numbers in the reverse order.
I have done this so far:
Code:
#include <stdio.h>
#include <stdlib.h>
main()
{
int arr[10];
int BUFFSIZE = 10;
char buffer[BUFFSIZE];
int i=0;
int *pa;
int z=9;
int a;
while (i<10){
printf("Enter an integer:\n");
fgets(buffer,BUFFSIZE,stdin);
if ( feof(stdin)){
printf("Finished\n");
break;
}
arr[0]= atoi(buffer);
i++;
}
while(z>=0){
pa=&arr[z];
a=*pa;
printf(a);
z--;
}
}
I do not really understand where i am going wrong (maybe because i might not fully understand pointers yet). Also I do not understand why the feof function is needed in this case.
Any help would be really appreciated.
Thanks