Ok, I have been given an assignment to do but dear god its killing me. Here are the first couple of questions, though I have replaced the example to "An example" as I want to try and do mine myself...based of help :lol: . Task 1. Type the given sentences or save the given text into the memory of one string variable. Let us assume that the given string is written from file into variable. Output of this task should be: MyString = “An example". This part I'm sure I can do, that's just making a cstring that contains "An example" right? The bit that just threw me off is the bit in red. Task 2. Find the longest word in the paragraph. You may use any method you choose, however you may wish to consider using the string length function strlen(). Output of this task should be: LongestWord = “example†Now for this part I'm thinking that I have to split the words in the string up and compare the words and then just output the longest. I just don't know where to start. So If anyone could upload a code or give me some pointers that would help, this is due next week and there are a total of 8 tasks :nope: .
Hrm, it looks like you're trying to get the longest word in the sentence? I don't know because I only skimmed through your post due to lack of time. I'll quickly post a small solution for you! So what you want to do is have your string sentence and you want to use a method that will count the places of the sentence array until you find a space. That space is what tells you where one word starts, and another begins. So, using that space we count up all the arrays into variables and then using simple if then statements we check to see if one word is bigger than the other, ruling out all but the biggest one. Hope that helps, if im off topic then sorry I couldnt read the full post because I have to go to work! Hee hee.
Thanks for that, I think after reading your post I have to use strtok to seperate each words, then use a loop to go through and count all of the letters in each word to see which is the longest....I think. Thanks anyway, I'm making slow progress, I've actually learnt that I have to #include <fstream> to get the "Hello World" (in my example)text from a file. I'll keep you posted.