From the screenshot it appears you typed Ctrl-Z to signal the end of file to your program. While this works in legacy systems such as MS/DOS and the Windows terminals, this key combination has a different meaning on unix systems such as linux: it causes the current process to be suspended by its the running shell parent. The process can be resumed later with the fg
command.
To signal the end on file on this system, you should type Ctrl-D instead.
Your program should produce the expected result then. The code seems OK, albeit it is quite confusing to name string
an int
variable that gets a single byte from getchar()
. Such a variable is usually named c
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…