Here's what an implementation of my suggestions would look like:
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
/* arbitrary values */
#define IN_SIZE 16
#define OUT_SIZE (IN_SIZE * 3) + 1
void
clr_stdin (char *s)
{
char ch, *p;
if ((p = strchr (s, '\n')) == NULL)
while ((ch = getchar()) != '\n' && ch != EOF)
;
else *p = '\0';
}
int
main (void)
{
char inbuf[IN_SIZE], outbuf[OUT_SIZE]; int i;
char *alpha[] = {
"ABC","DEF","GHI","JKL","MNO","PQR","STU","VWX","YZ"
};
while (1)
{
printf ("\nEnter your numbers > ");
if (fgets (inbuf, IN_SIZE, stdin))
{
if (!(isdigit (*inbuf)))
break;
clr_stdin (inbuf);
*outbuf = '\0';
for (i = 0; inbuf[i] != '\0'; i++)
{
if (isdigit (inbuf[i]) && inbuf[i] != '0')
strcat (outbuf, alpha[(inbuf[i]-'0')-1]);
}
if (*outbuf == '\0')
strcat (outbuf, "(invalid)");
printf ("Your output: %s\n", outbuf);
}
}
printf ("\nGood bye\n\n");
return 0;
}