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
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
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
strings are easier to avoid memory problems with, and have a lot of additional functionality that's helpful.
If you're still using C strings (arrays of chars), then look into strstr() and memmov().
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks