當前位置:編程學習大全網 - 編程軟體 - 將字符串末尾的空格去掉,用指針編程,我的C程序錯在哪裏?

將字符串末尾的空格去掉,用指針編程,我的C程序錯在哪裏?

修改後的C程序:

#include<stdio.h>

#include<string.h>

void sckg(char *a)

{

int i;

for(i=strlen(a)-1;a[i]==' ';i--);

a[i+1]='\0';

}

int main()

{

char a[100]; //修改處1:指針a必須有具體的地址

printf("please enter the string:\n");

//scanf("%s",a); //修改處2:%接收字符串時,遇到空格、跳格、回車止

gets(a); //修改處3:可以接收包含空格、跳格、回車在內的各種字符

sckg(a);

printf("%s",a);

return 0;

}

  • 上一篇:老馬三鑰匙損壞怎麽打火
  • 下一篇:編程初學者為什麽要學Java編程
  • copyright 2024編程學習大全網