please help me ,check the program .
if input the text like this "nice to meet you",the output right,no problem,but if input "nice to meet you too",the result is "nice meet you to",how should i do?

#include"stdio.h"
#define n 100
void del_char(char str1[n],char str2[])
{
  char str[n],*p1,*q,i,j;
  p1=str1;
  q=str;
  *q=*p1;
  i=0;
  while(*p1!='\0')

       {
          {
             if(*p1==str2[i])
                 {
                    p1++;
                    i++;
                    if(*p1==str2[i])
                    {
                       p1++;
                       i++;
                       if(*p1==str2[i])
                       {
                       p1++;
                       i++;
                        }
                       else
                       {
                       q++;
                       }
                      }
                    else
                    {
                     q++;
                     }
                 }
                 else
                    {
                    p1++;
                    q++;

                    }
        *q=*p1;
          }
        i=0;
      }
        printf("%s\n",str);
}
 main()
{
char str1[n],str2[]={"to "};
 
printf("please enter a text and includ 'to':\n");
 gets(str1);
 printf("remove 'to',remaining :\n");
 del_char(str1,str2);
 getch();}

Edited 6 Years Ago by Nick Evan: Added code-tags

Unless you are required to use pointers it might be easier to use strstr() to find the location of the word " to " (put a space before and a space after so that it doesn't pick up the word "too" or any other word that contains "to".

This article has been dead for over six months. Start a new discussion instead.