Thread: Still get error even if i changed a lot..

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    5

    Still get error even if i changed a lot..

    hi again..

    i made program again..but still makes error..i really dont know..why..

    can you guys tell me where...thanks so much



    #include<iostream.h>
    #include<string.h>



    using namespace std;



    void search_and_replace(char *text, char *s, char *r);



    int main()

    {

    const char text[256] = "You can find and replace any part of this line using this program.";

    char copy[256];

    strcpy(copy, text);



    // Search demo



    cout << "Original test is ..." << endl;

    cout << text << endl << endl;



    cout << "Searching..." << endl;

    search_and_replace(copy, "find", "search");

    cout << copy << endl;



    strcpy(copy, text);

    cout << "Searching..." << endl;

    search_and_replace(copy, "and", "&");

    cout << copy << endl;



    strcpy(copy, text);

    cout << "Searching..." << endl;

    search_and_replace(copy, "this line", "a sentence");

    cout << copy << endl;



    strcpy(copy, text);

    cout << "Searching..." << endl;

    search_and_replace(copy, "this", "the");

    cout << copy << endl;



    return 0;

    }



    void search_and_replace(char *text, char *s, char *r)

    {

    string strText = text;

    string search = s;

    string replace = r;



    cout << "Replacing..." << endl;



    basic_string <char>::size_type index;

    index = strText.find(search);



    // If search text is not found

    if ( index == string::npos )

    {

    cout << "No search text found." << endl;

    return;

    }



    // Delete search text

    strText.erase(index, search.length());

    // Insert replace text

    strText.insert(index, replace);

    // Copy to text

    strcpy(text, strText.c_str());

    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    http://cboard.cprogramming.com/showthread.php?t=89055

    You will not receive help if you don't smarten up.

    As I told you the last time, read my signature, but also read this: http://www.catb.org/~esr/faqs/smart-questions.html

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    5
    hey dude i just need some help

  4. #4
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Quote Originally Posted by icefire99 View Post
    hey dude i just need some help
    u
    s
    e

    c
    o
    d
    e

    t
    a
    g
    s

    a
    n
    d

    i
    n
    d
    e
    n
    t
    a
    t
    i
    o
    n

    t
    o

    m
    a
    k
    e

    y
    o
    u
    r

    c
    o
    d
    e

    a
    t

    l
    e
    a
    s
    t

    r
    e
    a
    d
    a
    b
    l
    e
    .


    There, I helped you.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Is it too much to ask that you conform to basic rules to receive help for free?

    • You didn't tell us where the error is.
    • You didn't properly use code tags.
    • You opened another topic on the same subject because you let the other one get so old.
    • You ignored correction in the previous posts.


    What are you expecting?

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    5
    hahahah thanks so much~ sit infront of computer waste whole life nerd ~just typing ........~~

    with ........in thick glass~~~~~~~~~~~~loosers~~

  7. #7
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Quote Originally Posted by icefire99 View Post
    hahahah thanks so much~ sit infront of computer waste whole life nerd ~just typing ........~~

    with ........in thick glass~~~~~~~~~~~~loosers~~
    testing the reaction speed of our new moderators, aren't you

    and believe me you wouldn't talk so smart if you stood in front of me in real life.

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Calling someone a nerd because you're too stupid or thickheaded to follow rules really is going to be productive.

    I understand you might like music. You have to put effort into music if you wish to learn to play an instrument. Same with programming. It isn't for lazy people. Find something else to do or shape up.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    hahahah thanks so much~ sit infront of computer waste whole life nerd ~just typing ........~~

    with ........in thick glass~~~~~~~~~~~~loosers~~
    How old are you?

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Closing the thread. The OP apparently doesn't want help, just his work done for him.

    Insulting the people you ask is not the way to achieve this.
    Last edited by CornedBee; 04-26-2007 at 03:55 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easier way of concatenating a lot of strings?
    By Evenstevens in forum C Programming
    Replies: 2
    Last Post: 05-09-2009, 01:29 PM
  2. Need a lot C programming help PLEASE!
    By copelli39 in forum C Programming
    Replies: 11
    Last Post: 04-21-2009, 09:37 PM
  3. Not much has changed in four years...
    By Eibro in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-18-2002, 09:11 PM
  4. How has this array been changed?
    By Agha in forum C Programming
    Replies: 4
    Last Post: 04-09-2002, 10:43 AM
  5. When is the server being changed?
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-18-2001, 11:08 PM