I'm trying to generate the following output:
0.1
0.12
0.123
0.1234
...
0.123456789
My code uses string/char arrays and some pointer data types that I'm not familiar with.
Code was taken from here to help get started, but I get the following output of gibberish.
Here is the code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main()
{
char *str = "0.";
char digit = '0';
size_t len = strlen(str);
int i = 1;
while(i<10)
{
printf("i: %d\n",i);
char *temp = malloc(len + 1 + 1);
len = strlen(temp);
digit = i + '0';
temp[len] = digit;
char string[len];
strcpy(string,temp);
free(temp);
printf("%s\n\n",string);
i = i +1;
}
}
What needs to be modified to get the data types to work correctly together?