?
Solved

It may be a logic question in setting increments,think you very much

Posted on 2003-03-01
5
Medium Priority
?
214 Views
Last Modified: 2010-04-15
I want to delete every characters ,which raise in string test,in string deled.But I don't know how to set the sentence ++deled.Think you very much.
The code is

#include <stdio.h>
#include <string.h>

void delchar (char *deled,char *test);

main ()
{
        char p_deled[100],p_test[100];
        printf("input p_deled\n");
        scanf("%s",p_deled);
        printf("input p_test\n");
        scanf("%s",p_test);

        delchar(p_deled,p_test);

        return 0;
}

void delchar (char *deled,char *test){
        int len_deled,len_test,i,j;
        char *p,*q,*orig_deled = deled,*orig_test=test;

        len_deled = strlen(deled);
        len_test = strlen ( test );

        for (i=0; *deled != '\0' && i<=len_deled;){
                while (*test != '\0'){
                if ( *deled == *test ){
                        for ( j=i,p=deled,q=deled ;*p != '\0';){
                                *p++ = *++q;
                                ++test;
                                ++j;
                        }
                }
                if ( *deled != *test )
                        ++test;
                }
                test = orig_test;
                ++deled;/*bugbug*/
                ++i;
        }

        printf("%s\n",orig_deled);
}
0
Comment
Question by:safty_wire
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Expert Comment

by:Exceter
ID: 8050502
>> I want to delete every characters ,which raise in string test,in string deled.But I don't know how to set the sentence ++deled.

I'm terribly sorry but I am not sure what you are asking. Could you be so kind as to explain your problem in a little more detail?

Exceter
0
 

Author Comment

by:safty_wire
ID: 8051391
Please aplogise me.My English is very terrible,because
English is not my mother tongue.
I want to do this if a charactor which belong to string deled ,a paramter of function delchar,appear in  
the string test,another paramter of function delchar,then delete it.
Lake this input bitupbitup,the string deled,and bi,the string test,then I can get correct answer tuptup.
But what confuse me is that when I input bibibibi ang
bi I will get a wrang answer bbb.
I believe that skunk is the experence ++deled which I remarked with sentence /*bugbug*/,but I don't konw how to cope with it.Oh!It make me exhaust.
0
 

Accepted Solution

by:
javabeanx earned 80 total points
ID: 8052615
Yes it is the problem with ++deled .
use the variable flag.
the deled must be incremented only when none of the characters in the test string  has occured.This is the changed code:

void delchar (char *deled,char *test){
       int len_deled,len_test,i,j;
       int flag=0; /*add*/
       char *p,*q,*orig_deled = deled,*orig_test=test;

       len_deled = strlen(deled);
       len_test = strlen ( test );

       for (i=0; *deled != '\0' && i<=len_deled;){
            flag=0; /*add*/
            while (*test != '\0'){
            if ( *deled == *test ){
                 for ( j=i,p=deled,q=deled ;*p != '\0';){
                      flag=1;
                      *p++ = *++q;
                      ++test;
                      ++j;
                 }
            }
            if ( *deled != *test )
                 ++test;
            }



            test = orig_test;
            if(!flag) /*add*/
            ++deled;/*bugbug*/
            ++i;

       }

       printf("%s\n",orig_deled);
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10058680
Nothing has happened on this question in more than 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by javabeanx.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question