my problem is in convert a char to string
i have to pass to strcat() a char to append to a string, how can i do?
thanks!
#include <stdio.h>
#include <string.h>
char *asd(char* in, char *out){
while(*in){
strcat(out, *in); // <-- err arg 2 makes pointer from integer without a cast
*in++;
}
return out;
}
int main(){
char st[] = "text";
char ok[200];
asd(st, ok);
printf("%s", ok);
return 0;
}
Since
okis pointing to an uninitialized array of characters, it’ll all be garbage values, so where the concatenation (bystrcat) will start is unknown. Alsostrcattakes a C-string (i.e. an array of characters which is terminated by a ‘\0’ character). Givingchar a[200] = ""will give you a[0] = ‘\0’, then a[1] to a[199] set to 0.Edit: (added the corrected version of the code)