Hi everyone,
Can someone please explain my mistake. The code is supposed to convert characters from an array into their respective ascii integers, and append a 0 if the number is less than 3 digits long. It then supposed to put it all together into one string. Many thanks.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
char file[] = "This is a test";
char *ptr = file;
int length = strlen(file);
int i, numbers[length];
for (i =0; i <= length; i++){
numbers[i] = *ptr;
printf("%i\n", numbers[i]);
ptr++;
}
//////Problem is here//////////
char stringout[100000000] = "";
char temp[4];
for (i =0; i <= length; i++){
sprintf(temp, "%i", numbers[i]);
if (strlen(temp) == 2){
temp = strcat("0", temp);
}
stringout = strcat(stringout, temp);
}
///////////////////////////////
return 0;
}