有没有什么代码 添加后可以去除输出函数的代码
#include <stdio.h>#include <string.h>
int main()
{
char str[]="A D D C";
int i,j,k;
j=strlen(str)-1;
for(i=0;i<j;i++,j--)
{
k=str;
str=str;
str=k;
}
printf("%s\n",str);
return 0;
}
如题 就是加入某代码 我的输出结果中会没有空格 空格也是一个字符……… bin554385863 发表于 2019-10-27 18:02
空格也是一个字符………
就是去掉某个字符么{:10_258:} 如何去掉特定字符我不是很会 大一小白一个 本帖最后由 bin554385863 于 2019-10-27 23:28 编辑
/*
这段代码的作用是去除字符串中不是字母的字符
*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
char *func(char *cstr)
{
int count = 0, m = 32;
char *ptr = (char *)malloc(sizeof(char) * m); //申请空间
for (char *i = cstr; *i != '\0'; i++)
{
if (isalpha(*i))//判断是否为字母
{
ptr = *i;
ptr = '\0';
count++; //计算大小
if (count > (m / 2)) //空间不足时.动态申请空间
{
m += 16;
char *tmp = (char *)malloc(sizeof(char) * m);
tmp = {0};
strcpy(tmp, ptr);
free(ptr);
ptr = tmp;
}
}
}
return ptr;
}
int main(int argc, char const *argv[])
{
char str[] = "A D D C";
printf("%s", func(str));
return 0;
}
---------------------------------------------------------------------------------------
Microsoft Windows [版本 10.0.16299.1087]
(c) 2017 Microsoft Corporation。保留所有权利。
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.26.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-kexbbu1a.bor --stdout=Microsoft-MIEngine-Out-mm3agyom.2cm --stderr=Microsoft-MIEngine-Error-mo4hduvp.fz1 --pid=Microsoft-MIEngine-Pid-4njrtxpr.bc1 "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
ADDC
E:\Users\86184\Documents\Code>
页:
[1]