
关于C语言中利用指针和数组,删除字符串前面和后面的空格的问题。
#include<stdio.h>#include<string.h>voidtransform(char*s){char*p=s;char*k;while(*p++!=...
#include <stdio.h>
#include <string.h>
void transform(char *s)
{
char *p=s;
char *k;
while(*p++ !='\0')
{
if(*p==NULL)
{
k=p;
while(*k!='\0')
*k=*(k+1);
}
}
}
void main()
{
int u;
char a;
printf("please input your strings,thankyou \n");
scanf("%s",&a);
u=strlen(a);
char s[100];
transform(s);
printf("%s",s);
} 展开
#include <string.h>
void transform(char *s)
{
char *p=s;
char *k;
while(*p++ !='\0')
{
if(*p==NULL)
{
k=p;
while(*k!='\0')
*k=*(k+1);
}
}
}
void main()
{
int u;
char a;
printf("please input your strings,thankyou \n");
scanf("%s",&a);
u=strlen(a);
char s[100];
transform(s);
printf("%s",s);
} 展开
2个回答
展开全部
你这代码错得多了点。
声明的a是字符,用scanf("%s",&a);为其输入一个字符串,能放得下吗?
u=strlen(a);——a就是一个字节,用不着测;若这样测,恐怕编译都过不了。
while(*p++ !='\0')这样的写法,循环体里的p已是增量后的p了,不知注意了没有?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询