when i run this program, it doesnt do the last printf that says 'darn glad to meet you...' it just CR+LF. ive copied this straight from a book, i dont understand why it wont work.
thanks to anyone who can help.Code:
#include <stdio.h>
#include <conio.h>
#define CR 0x0d
#define ESC ox1b
#define TAB 0x09
#define LF 0x0a
#define BACKSPACE 0x08
#define NULL 0
#define TRUE 1
#define FALSE 0
#define LENGTH 15
void input(char *string, int length);
void main()
{
char string[LENGTH];
printf("Whats your name?");
input(string, LENGTH);
printf("Darn glad to meet you, %s!\n", string);
}
void input(char *string, int length)
{
int done = FALSE;
int index = 0;
char ch;
string[0] = NULL;
do
{
ch = getch();
if( index == length)
{
switch(ch)
{
case CR:
break;
default:
ch = NULL;
break;
}
}
switch(ch)
{
case CR:
putchar(ch);
putchar(LF);
string[index] = NULL;
done = TRUE;
break;
case BACKSPACE:
if(index==0)
{
break;
}
else
{
putchar(ch);
putchar(' ');
putchar(ch);
index--;
break;
}
case NULL:
break;
default:
putchar(ch);
string[index] = ch;
index++;
break;
}
}
while(!done);
}