You can not fill an int
array with zero-padding numbers.
because the int type will store just the integer values, Consider below example:
#include <stdio.h>
int main(){
int a = 0001;
printf("%d\n", a);
return 0;
}
The result of above code is:
1
And that's it.
By the way, if you want to have zero-padding numbers, you should print them to an array of characters and use sprintf
instead printf
, look at below example:
#include <stdio.h>
//include other necessary libraries.
int main(){
char* randomNumbers[1000];
//while your numbers are at most 4 digit, I will allocate just 4 bytes:
for(int i = 0; i < 1000; i++){
randomNumbers[i] = (char*) calloc(4, sizeof(char));
}
//here we go to answer your question and make some random numbers which are zero-padding:
for(int i = 0; i < 1000; i++){
int a = rand() % 1000;
sprintf(randomNumbers[i], "%03d", a);
}
}
The randomNumbers
array is your suitable array.