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. HHEELLPP!!!

HHEELLPP!!!

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
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.
  • S Offline
    S Offline
    Sunnygirl
    wrote on last edited by
    #1

    hello @all, i want to have a string with n letters. my program provided these letters by coincidence. for example: i want to have a string with a length of 1000. i enter this in my dialog, that i want to have a string with 1000 letters. Now, these 1000 letters (e.g. from the letters ABCD) must be provided by coincidence. after that, the string should look (e.g.) like that: CString str="AAABBCDDDABBCDDACCDD...." how can i program a programm with this function? can anybody help me? thank you very much! sunny

    N T 2 Replies Last reply
    0
    • S Sunnygirl

      hello @all, i want to have a string with n letters. my program provided these letters by coincidence. for example: i want to have a string with a length of 1000. i enter this in my dialog, that i want to have a string with 1000 letters. Now, these 1000 letters (e.g. from the letters ABCD) must be provided by coincidence. after that, the string should look (e.g.) like that: CString str="AAABBCDDDABBCDDACCDD...." how can i program a programm with this function? can anybody help me? thank you very much! sunny

      N Offline
      N Offline
      noksi
      wrote on last edited by
      #2

      Hi, I suggest you 2 solutions First: CString strMyWord = ""; int iSizeOfMyString = GetSizeFromDialog(); for (int i=0; i

      1 Reply Last reply
      0
      • S Sunnygirl

        hello @all, i want to have a string with n letters. my program provided these letters by coincidence. for example: i want to have a string with a length of 1000. i enter this in my dialog, that i want to have a string with 1000 letters. Now, these 1000 letters (e.g. from the letters ABCD) must be provided by coincidence. after that, the string should look (e.g.) like that: CString str="AAABBCDDDABBCDDACCDD...." how can i program a programm with this function? can anybody help me? thank you very much! sunny

        T Offline
        T Offline
        Terry ONolley
        wrote on last edited by
        #3

        If I understand you correctly, you want to allow the user to specify the length of the string and the string itself will be composed of a random assortment of the letters A-D. Assuming that the length of the string is passed to this function as nStringLength, you could try: CString GetString(int nStringLength) { char* buff; // holds chars as they are assigned int index = 0; // index for moving through buff char ch; // the current char CString csResult; // the resulting, finished string buff = malloc(nStringLength + 1); // allocate the memory for your string srand(1); // seed the random number generator while(index < nStringLength) // loop through as many times as required { ch = char((rand() % 4) + 65); // get a random number and get it's modulus 4 // (ie numbers from 0 to 3). Add 65 to it to arrive // at the ascii values corresponding to A,B,C & D buff[index] = ch; // add the new character to the string index++; // increment the index } buff[index] = '\0'; // Add the null terminator to the string csResult = buff; return csResult; } I'm going to live forever or die trying!

        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