Auto commit
This commit is contained in:
parent
64c22c4d2f
commit
634e5a21fb
@ -195,3 +195,51 @@ main()
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### C语言-6
|
||||||
|
|
||||||
|
```c
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
【程序设计】编写函数rtrim,用来删除字符串尾部的空格,首部和中间的空格不删除。例如:字符串为:" A BC DEF ",
|
||||||
|
删除后的结果是" A BC DEF"。要求函数形参采用指针变量。
|
||||||
|
测试输入: A BC DEF
|
||||||
|
测试输出: A BC DEF
|
||||||
|
说明:测试输入中,A前有4个空格,F后有5个空格
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,否则不得分。
|
||||||
|
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
void rtrim(char *p);
|
||||||
|
char s[100];
|
||||||
|
gets(s);
|
||||||
|
rtrim(s);
|
||||||
|
puts(s);
|
||||||
|
}
|
||||||
|
void rtrim(char *p)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
/**********Program**********/
|
||||||
|
while(*p != '\0'){
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
p--;//定位到结束符前的位置
|
||||||
|
while(*p==' '){//如果当前指针位置是空格则指针向前移
|
||||||
|
p--;
|
||||||
|
}
|
||||||
|
p++;//移动当前位置后一个空格位
|
||||||
|
*p='\0';
|
||||||
|
|
||||||
|
|
||||||
|
/********** End **********/
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### C语言-7
|
||||||
|
|
||||||
|
```c
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user