Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-01
5
Medium Priority
?
221 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
4 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-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.

572 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