Archived

This topic is now archived and is closed to further replies.

how do I clear a string?

This topic is 5208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

when my strings are printed with text out they have black rectangles in it, I tried char szPrime01 [12] = {" "}; which got rid of some of the rectangles in the middle but the first one and last one are still there, if I add more spaces I get an error about the size

Share on other sites
Do you mean the gdi function TextOut? What kind of rectangles? Do you mean a background rectangle, similar to how selected text looks, or do you mean rectangles that indicate a missing font character? The artifact could be the result of the way that many Windows GUI text out put functions render new line characters. Try using "\r\n" instead of just "\n". Maybe that will do the trick.

[edited by - lessbread on February 20, 2004 7:15:54 PM]

Share on other sites

szPrime01 [12] = {"\0"};

Share on other sites
I dont understand why you would get non-printing chars at the start though. Any chance you post all the relivant code?

Share on other sites
char szPrime01 [12] = {"\0"}; didn't work

strcpy ( szPrime04, szPrime05);

sprintf ( szPrime05, TEXT (" %u "), realnum);

TextOut (hdc, cxChar * 20, cyChar * 0, szPrime01, 12) ;

I think thats all the relivant stuff

oh yea and the rectangles look like fat I's black

[edited by - ppcthug on February 20, 2004 12:17:20 AM]

Share on other sites
Your code makes no sense. You print szPrime01 but you never show what you've set it to.

The "fat Is" mean you're trying to print invalid characters -- specifically, characters that aren't in the current font. When that happens, Windows defaults to an outlined square or filled-in rectangle. Example: 

Please show us how szPrime01 is set.

~CGameProgrammer( );

[edited by - CGameProgrammer on February 20, 2004 12:24:14 AM]

Share on other sites
Use ZeroMemory() on the string

Share on other sites
quote:
Original post by CProgrammer
Use ZeroMemory() on the string

He''s not trying to make the string blank... if he was, doing "szPrime01[0] = 0" would clear it, there''s no need for clearing the entire array anyway.

~CGameProgrammer( );

Share on other sites
sorry, I'm a bit distracted

void PrimeGenerator (){if (divisor >= realnum)   {                            // std::cout << "Prime number: " << realnum << "\n";  doesn't work in win32   /* cannot copy strings or arrays!!!   szPrime01 = szPrime02;   szPrime02 = szPrime03;   szPrime03 = szPrime04;   szPrime04 = szPrime05;   */      strcpy ( szPrime01, szPrime02);   strcpy ( szPrime02, szPrime03);   strcpy ( szPrime03, szPrime04);   strcpy ( szPrime04, szPrime05);      sprintf ( szPrime05, TEXT (" %u  "), realnum);      // szPrime05 = realnum; can't convert from unsigned int to char string      InvalidateRect (hwnd, NULL, TRUE);                                                                                                                      realnum += 2;   divisor = 2;   count++;      if (count >= 15)      {              OnOff = false;                                         // std::cout << "Do you want to quit?(y to quit)\n"; doesn't work in win32       // std::cin >> quit; same here              /*                    all work and no play yada yada yada       if ( quit == 'y' )                 break;          else                 count = 0;        */                  }                   }      if ((realnum % divisor) != 0)      {      divisor++;      }         else      {         realnum += 2;      divisor = 2;                  /*                        for some reasion this         if (fuse = 60000)         counter quit the program          {                         before it should have!?          break;          }        */      }            }

[edited by - ppcthug on February 21, 2004 2:43:12 AM]

[edited by - ppcthug on February 21, 2004 2:43:37 AM]

Share on other sites
Are any of those strings ever initialized? You really can''t just declare strings and start using them. Show use where you have char* szPrime01 = "string"; or something like that.

Tolerance is a drug. Sycophancy is a disease.

• 10
• 17
• 9
• 13
• 41