Use '
' and terminate your string with ''.
Additionally, you might try to use getche() to give a visual echo to the user and do some other general corrections:
#include <stdio.h>
#include <conio.h>
#define MAX_NAME_LENGTH 20
int main()
{
char ch, name[MAX_NAME_LENGTH];
int i=0;
clrscr();
printf("Enter a string:");
while ( ((ch=getche())!='
') && (i < MAX_NAME_LENGTH - 1) )
{
name[i]=ch;
i++;
}
name[i] = '';
printf("%s
",name);
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…