使程序从文本中删除数字 [英] Make program to delete number from text

查看:69
本文介绍了使程序从文本中删除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i want to make program using pointer that delete all number from text, for example when the input from keyboard is "ab1c9" then the program result "abc" only. so i actually think about using the pointer and overwrite it using the word without number result but it didntesnt seem work :/ and im still confuse about when should i use * or not

 #include <stdio.h>
 #include <stdlib.h>

  void deldigit(char *str)
 { char *res = str;
 int count=0;
  while(*str!='\0')
  {
  if(*str>='1' && *str<='9')
     { count++;}
  else
     {*(str-count)=*str; /* want this *str after increment to    overwrite *(str-count) */
             }
       str++;}
    *(str - count)= '\0';
   printf("%s",res);
   }
  int main()
  { char str[100];

   printf("inset word");
    scanf("%s",&str);
       deldigit(str);
  return 0;
   }





我的尝试:





What I have tried:

i tried to make two pointers that point to the same start of the array, but basically to make result not overlap, first pointer function is where all digits were removed and looking for digit, while the second one showing the result? i still confuse about the purpose of second pointer. 
 and also is it possible to declare char *str[100] in main?




and

scanf("%s",&str);

我应该使用&或不是?

should i use & or not?

推荐答案

首先使用你的第二个指针:

Start by using your second pointer:
void deldigit(char *str)
   { 
   char *res = str;
   while(*str!='\0')
      {
      if(!(*str>='1' && *str<='9'))
         {
         *res++ = *str;
         }
      str++;
      }
   *res = '\0';
   }


这篇关于使程序从文本中删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆