-
Filling an array
I am trying to fill an array with 10 integers starting from 5 by 1. I dont see what is wrong with my code. I'm getting junk data.
Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int ia[10], *p, x;
x=0;
printf("Contents of array ia:\n");
while (x<10) {
ia[x]=x+5;
x++;
printf("%d\n", ia[x]);
}
return 0;
}
-
Swap the order to:
Code:
printf("%d\n", ia[x]);
x++;
-
-
Put x++ after printf():
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int ia[10], x;
printf("Contents of array ia:\n");
x = 0;
while (x < 10) {
ia[x] = x + 5;
printf("%d\n", ia[x]);
x++;
}
return 0;
}
---EDIT---
sob....