So currently just about tried everything with the best of my knowledge to get this to work but I have been hitting a wall it seems.
Code:
#include <stdio.h>#include <string.h>
main(){
int i, len;
char name[20], length;
unsigned x;
char len_str[10];
write(1,"Enter your last name: ",21);
fflush(stdout);
len = read(fileno(stdin),name,20);len--;name[len] = 0;
write(1,"Name entered is ",16);
write(1,name,len);
write(1," length is ",11);
// !!!!THIS PART!!! //
// My attempt to work around with no luck //
len_str[0] = len;
len_str[1] = 0;
write(1,len_str, 2);
write(1,". \n", 3);
//Clearly works here//
printf("%d\n", len);
}
I have tried casting write(1,(char) len, 1); tried passing it without casting, tried to make a pointer pointing to it and then passing that through but no luck empty space where the number should appear. I know that len is correct because of printf... but the goal is to not use printf just write() and not putchar, or >> and im having no luck finding any solutions.
This is only a section of the code without my comments (sorry) just trying to find a solution to the writing issue, maybe i missed something and a source of where i can go to find the answer could be of help (or a solution ), thanks!