Closed Thread
Results 1 to 5 of 5

Thread: Remove a word from sentence using arrays

  1. #1
    Hawk1 is offline Learning Programmer
    Join Date
    Sep 2008
    Posts
    70
    Rep Power
    0

    Remove a word from sentence using arrays

    Well i've made it to the end of my self-taught c++ book and there are a few topics i would like to clear up.

    the first one being how to do remove a word from a sentence using arrays.

    For example, something like this.

    Write a function called deleteit that will delete a word from a sentence.

    Please input a sentence: "i really dont like this assignment"

    The function should take as arguments 2 arrays of chars. The first array will contain the sentence. The second array will contain the word to be deleted.

    please input the word you would like deleted: dont
    Print out the sentence when the function returns.

    Your sentence was: i really like this assignment

    Your function should also return the number of characters deleted if the word was found in the sentence. It should return -1 if the word wasn't found.

    I deleted ____ characters from that sentence.

    I THINK, THATS WHAT its asking for right?

    where do you think the best place is to start on this?
    reps for help like always!
    thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Remove a word from sentence using arrays

    1) Get a new book. You should NOT be using arrays of chars in a C++ course. Use the string class instead.
    2) If this is a homework assignment, make use of the available functions, such as strchr() that are available.
    3) use this site for more info: cstring (string.h) - C++ Reference
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Hawk1 is offline Learning Programmer
    Join Date
    Sep 2008
    Posts
    70
    Rep Power
    0

    Re: Remove a word from sentence using arrays

    no hw assignments for me, all self taught stuff just because i want to learn.

    whats wrong with using arrays of chars? chars of class isnt till next chapter

  5. #4
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Remove a word from sentence using arrays

    strings are easier to avoid memory problems with, and have a lot of additional functionality that's helpful.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Remove a word from sentence using arrays

    If you're still using C strings (arrays of chars), then look into strstr() and memmov().

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2011, 11:05 PM
  2. Replies: 1
    Last Post: 12-14-2009, 10:42 AM
  3. converting english sentence into first order logic
    By ailearner in forum General Programming
    Replies: 3
    Last Post: 01-16-2009, 07:09 PM
  4. Finish the sentence:)
    By Donovan in forum Games
    Replies: 9
    Last Post: 10-29-2008, 11:32 AM
  5. Replies: 3
    Last Post: 12-29-2007, 04:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts