For my homework I have to swap and int with a character. For example if the user types in 1 the output should be "one". this should work from zero to 5.
My Idea would be to implement a char array that looks like this.
*string[] = { "zero\0", ....., "five\0"}
Then I would implement it in a code like this.
#include <stdio.h>
int main()
{
int c;
while((c=getchar())!=EOF)
{
putchar(c);
}
return 0;
}
So since I am only allowed to use putchar and getchar and no heap. This would be my approach: I would create a for loop that would print out the every letter until \0 is reached.
Is this the right approach?
\0at the end. 2) ifi == 0, thenstring[i]will evaluate to"zero"(or, in your case"zero\0"). - Grooonewhen the user types in1. The string literal"one"already contains 4 characters, the last being'\0'. - Groo