1
2
3
|
char
s[100];
fgets
(s,sizeof(s),stdin);
if
(
'\n'
==s[
strlen
(s)-1])
s[
strlen
(s)-1]=0;
|
然后用fgets,输入:123abc[回车]
输入结束后,实际存放为123abc\n\0,
因此,需要把\n替换为\0
证明:('\n'对应10,'\0'对应0)
[root@localhost MyTest]# gcc 2_句子逆序.c
[root@localhost MyTest]# ./a.out
Input a sentence:
123abc
len:7
x=10, y=0