I am trying to write a code in C language to store the following series of numbers in a string "0.123456789101112131415...".
I am tried this code:
char num[2000], snum[20];;
num[0] = '0';
num[1] = '.';
for(int i = 1; i < 20; i++) {
sprintf(snum, "%i", i);
strcat(num, snum);
printf("%s
", num);
}
I included the following libraries:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
I get this when I print the variable "num":
"0." + some garbage (sometimes I get "0.N", sometime "0.2", sometimes "0.R", and so on).
What am I doing wrong?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…