慕碼人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);
}

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);
- 3 回答
- 0 關注
- 333 瀏覽
添加回答
舉報
0/150
提交
取消