Results 1 to 8 of 8

Thread: not displaying 1 character

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    not displaying 1 character

    Code:
    for(i=1; i<=sizeof(big); i++)  {
    if(big[0] == '*')  {
    StartCopy == true;
    //MessageBox(ghWnd_Main, "COPY = TRUE!", "Copy Test", MB_OK);
    }
    else if(StartCopy == true)  {
    linkURL[holder] = big[i];
    holder++;
    }
    //MessageBox(ghWnd_Main, linkURL, "linkURL", MB_OK);
    }
    MessageBox(ghWnd_Main, big[1], "big", MB_OK);
    SearchMode=3;
    heres a block of my code...why does the messagebox displaying big[1] show a whole string starting from 1???? I only want to use that character
    Last edited by SteveCRM; Nov 29th, 2001 at 07:07 PM.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    a char is not a c style string, a c style string is a character array that is null terminated. Copy the char into a string buffer of 2 chars with second char=0
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    didn't know that...thanks ked I'll give that a go!

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    having some trouble, could anyone stear me in the right direction?

    Code:
    char test;
    bool StartCopy = false;
    int holder = 1;
    for i=1; i<=sizeof(big); i++)  {
         test = big[1];
         if(test == '*')  {
              StartCopy == true;
              MessageBox(ghWnd_Main, "COPY = TRUE!", "Copy Test", MB_OK);
         }
         else if(StartCopy == true)  {
              linkURL[holder] = big[i];
              holder++;
         }
         //MessageBox(ghWnd_Main, linkURL, "linkURL", MB_OK);
    }
    //MessageBox(ghWnd_Main, &test, "test", MB_OK);
    I can't get it to check if the first character is a *...I want the "Copy Test" messagebox to pop up.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Arrays are indexed starting from 0. So the first letter is big[0].
    Harry.

    "From one thing, know ten thousand things."

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    doesn't get the messagebox to show up (i know there is a * in the string...but im checking with the loop to see if its the character Im on)

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try declaring the test char as:

    PHP Code:
    char *test
    Baaaaaaaaah

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Code:
    char test;
    bool StartCopy = false;
    int holder = 1;
    for i=1; i<=sizeof(big); i++)  {
         test = big[1];                    // point A
         if(test == '*')  {
              StartCopy == true;
              MessageBox(ghWnd_Main, "COPY = TRUE!", "Copy Test", MB_OK);
         }
         else if(StartCopy == true)  {
              linkURL[holder] = big[i];
              holder++;
         }
         //MessageBox(ghWnd_Main, linkURL, "linkURL", MB_OK);
    }
    //MessageBox(ghWnd_Main, &test, "test", MB_OK);
    Look at the bit of the code I have commented with 'point A'. You are assigning big[1] to the variable 'test' every time in the loop. big[1] is the second letter in the string, so you will always be checking the second letter. If you were intending to check every letter with that loop you should check big[ i ], or if you want to check the first letter, you should check big[0].

    Try this:
    Code:
    char test;
    bool StartCopy = false;
    int holder = 1;
    for i=1; i<=sizeof(big); i++)  {
         test = big[ i ];                    // point A - changed to big[ i ]
         if(test == '*')  {
              StartCopy == true;
              MessageBox(ghWnd_Main, "COPY = TRUE!", "Copy Test", MB_OK);
         }
         else if(StartCopy == true)  {
              linkURL[holder] = big[i];
              holder++;
         }
         //MessageBox(ghWnd_Main, linkURL, "linkURL", MB_OK);
    }
    //MessageBox(ghWnd_Main, &test, "test", MB_OK);
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

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



Click Here to Expand Forum to Full Width