为了账号安全,请及时绑定邮箱和手机立即绑定

关于c语言改错题,下面内容是删除字符串S中所有空格,请问错哪里?

关于c语言改错题,下面内容是删除字符串S中所有空格,请问错哪里?

C PHP
慕码人2483693 2021-12-02 11:07:53
急啊,#include"stdio.h"#include"string.h"void delspace();main(){ char s[81]="a b c d e f g";delspace(s[]);puts();getch();)void delspace(char*str){ int i,t; char ts[81]; for(i=0,t=0;str[i]!='\0';i++) if(isspace(*(str+i)) ts[t++]=str[i]; ts[t]='\0'; strcpy(*str,ts); getch();}有三个错,那个高手指点下啊!
查看完整描述

3 回答

?
白板的微信

TA贡献1883条经验 获得超3个赞

何止三个错啊,真佩服你,差不多每2行就有一个错误。一一指出实在太累了,直接给你正确的程序吧。
#include"stdio.h"
#include"string.h"
#include "ctype.h"
void delspace(char *str);
main()
{
char s[81]="a b c d e f g";
delspace(s);
puts(s);
}
void delspace(char*str)
{
int i,t;
char ts[81];
for(i=0,t=0;str[i]!='\0';i++)
if(!isspace(*(str+i))) ts[t++]=str[i];
ts[t]='\0';
strcpy(str,ts);
}



查看完整回答
反对 回复 2021-12-07
?
FFIVE

TA贡献1797条经验 获得超6个赞

错误1: 函数参数传递错误
delspace(s[]); 修改为 delspace(s);

错误2:基本语法错误
if(isspace(*(str+i)) 修改为 if(isspace(*(str+i))), 这里少一个括弧

错误3:逻辑错误
if(isspace(*(str+i))) 修改 if(!isspace(*(str+i)))
这里是要把非空格填写如ts中。

错误4:函数参数传递错误
strcpy(*str,ts); 修改为 strcpy(str,ts);



查看完整回答
反对 回复 2021-12-07
?
九州编程

TA贡献1785条经验 获得超4个赞

main() 函数下面的 } 变成了) main()里 delespace(s[]) 把[]去掉 puts() 改为puts(s);..

查看完整回答
反对 回复 2021-12-07
  • 3 回答
  • 0 关注
  • 267 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信