'Can not print out the elements of an array in a for-loop
Why can not I print out the elements of an array in a for-loop?
My environment is Windows 7 Maximum,
gcc (MinGW.org GCC-6.3.0-1) 6.3.0
I input the data from the prompt like 3 1 2 3.
I can do, e.g., printf("%" PRId64 " ", marray[2]) but from the for-loop it doesn't work.
Here is the source code:
#define __USE_MINGW_ANSI_STDIO 1
#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
size_t read_size() {
size_t x;
scanf("%lu", &x);
return x;
}
int64_t read_int64() {
int64_t x;
scanf("%" SCNd64, &x);
return x;
}
int main() {
size_t *size;
*size = read_size();
int64_t *marray = malloc(sizeof(int64_t) * *size);
for (size_t i = 0; i < *size; i++) {
marray[i] = read_int64();
}
for (size_t i = 0; i < *size; i++) {
printf("%" PRId64 " ", marray[i]);
}
free(marray);
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
