I am trying to create a program that creates a loop to enter different values in an array.
but the program is skipping values of i. I can't understand why..
#include<stdio.h>
int main (void)
{
char s[10];
int i;
for (i=1;i<=10;i++) {
printf("enter %d'th value of the array 's'\n",i);
scanf("%c",&s[i]);
}
printf("\n\nThe fifth value of the array is: %c", s[5]);
fflush(stdin);
getchar ();
return 0;
}
EDIT .. I looked for some help on the internet and managed to do this but funnily enough the loop keeps on going and i can't understand why
#include<stdio.h>
int main (void)
{
int i;
char myArray [5];
printf("\n___________Data Inputting__________________\n");
for (i=0;i<=5;i++){
printf("Enter value for %d: ",i);
scanf("%s",&myArray[i]);
}
printf("\n_____________________________\n");
printf("5'th value is: %c\n\n", myArray[i]);
fflush(stdin);
getchar ();
return 0;
}