Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can someone help, im new to C++

Can someone help, im new to C++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++javaquestionlearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mawmany2k
    wrote on last edited by
    #1

    I have a string containing the sentence: "a do cat from hello thomas d" My task is to read through the string, determine what is the shortest word(s) and what is the longest word(s) then display each. So for the sentence above, i will need to display the following: Biggest word(s)= thomas Smallest word(s) = a, d The problem i have is determining the longest and shortest word(s). This is my first attempt at C++ after Java for 6 months before i changed my course at college Please help me ..::M::..

    S H 2 Replies Last reply
    0
    • M mawmany2k

      I have a string containing the sentence: "a do cat from hello thomas d" My task is to read through the string, determine what is the shortest word(s) and what is the longest word(s) then display each. So for the sentence above, i will need to display the following: Biggest word(s)= thomas Smallest word(s) = a, d The problem i have is determining the longest and shortest word(s). This is my first attempt at C++ after Java for 6 months before i changed my course at college Please help me ..::M::..

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      The simplest way to do it is to use the MFC CString class. It's much like the Java String. Create a new project, choose MFC application, then dialog-based. From this point, you can use the MFC CString class.

      1 Reply Last reply
      0
      • M mawmany2k

        I have a string containing the sentence: "a do cat from hello thomas d" My task is to read through the string, determine what is the shortest word(s) and what is the longest word(s) then display each. So for the sentence above, i will need to display the following: Biggest word(s)= thomas Smallest word(s) = a, d The problem i have is determining the longest and shortest word(s). This is my first attempt at C++ after Java for 6 months before i changed my course at college Please help me ..::M::..

        H Offline
        H Offline
        Hari Krishnan Noida
        wrote on last edited by
        #3

        Hi, Try with following code snippet. ---------------------------------------------------------- :)CString strSentence = "a do cat from hello thomas d"; int iLongest = 0; //Initialize with minimum value. int iShortest = 1024; //Initialize with Big Value int nIndex; //Backup. If you dont want you can remove CString strHelper(strSentence); while(!strHelper.IsEmpty()) { if(-1 == (nIndex = strHelper.Find(' ', 0))) { nIndex = strHelper.GetLength(); //Last word strHelper.Empty(); } if(nIndex < iShortest) iShortest = nIndex; if(nIndex > iLongest) iLongest = nIndex; strHelper.Delete(0, nIndex+1); //Remove including space. } ----------------------------------------------------------

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups