I'm a beginner trying to create a recursion loop to learn the theory for an assignment, but I'm not sure why this function won't write variables to console. I feel like the answer is so simple but I've tested write(1, &n, 1) in different places throughout the program and it won't print, even though strings will print and the same function has worked for me before in other programs.
There are no errors, it just refuses to print.
#include <unistd.h>
void testloop(int n)
{
if (n < 10)
{
write (1, "test", 4);
write (1, &n, 1);
testloop(++n);
}
}
void test(void)
{
testloop(0);
}
int main(void)
{
test();
}
The string "test" will print, but not the variable n.
The current output is testtesttesttesttesttesttesttesttesttest
The only function I can use for the assignment is write(), so no printf(), unfortunately.