Thread: Decimal string to Char string Problem in Visual C++ window form application

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Question Decimal string to Char string Problem in Visual C++ window form application

    Good day. I am facing a problem. I am using Visual Studio C++ and wish to create a Window Form Application. The purpose to create this program is to show the encrypted text from a textbox in a small window.

    Below is my code:

    Code:
    String ^ Data1;
    String ^ Data2;
    int key = 'x';
    
    Data = richTextBox1 -> Text;
    
    int iLen = richTextBox1 -> Text -> Length; //define the string length
    
    for (int i=0 ; i < iLen ; i++)
    {
    Data1 += Data[i] ^ (int(key) * i + int(key) / (i+1)) % 255; //Encryption formula
    }
    
    MessageBox :: Show(Data1); //Show the encrypted text in window
    For above, if Data din't pass the Encryption Formula, i will show the exactly TEXT in the textbox. But Data undergo the encryption formula, The DATA1 show the TEXT in decimal value.

    As example:

    "1" = 49
    When i type "1", undergo the formula, so it must come out "I" in character form. But from my code above, it show decimal 73(decimal of char "I").

    How can i make it to show "I" rather than showing 73?

    Thanks in advance. Sorry for my bad English and Explanation.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Windows Forms Application is not actually C++, but another language called C++/CLI. This section is for ISO C++, not C++/CLI. In the future, it might be a good idea to post these in the teach board section. Just a FYI.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Moved to windows board
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Sorry...

    Quote Originally Posted by Salem View Post
    Moved to windows board
    Sorry all, I will move this thread to window board, thx all

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by ChongHan View Post
    Good day. I am facing a problem. I am using Visual Studio C++ and wish to create a Window Form Application. The purpose to create this program is to show the encrypted text from a textbox in a small window.

    Below is my code:

    Code:
    String ^ Data1;
    String ^ Data2;
    int key = 'x';
    
    Data = richTextBox1 -> Text;
    
    int iLen = richTextBox1 -> Text -> Length; //define the string length
    
    for (int i=0 ; i < iLen ; i++)
    {
    Data1 += Data[i] ^ (int(key) * i + int(key) / (i+1)) % 255; //Encryption formula
    }
    
    MessageBox :: Show(Data1); //Show the encrypted text in window
    For above, if Data din't pass the Encryption Formula, i will show the exactly TEXT in the textbox. But Data undergo the encryption formula, The DATA1 show the TEXT in decimal value.

    As example:

    "1" = 49
    When i type "1", undergo the formula, so it must come out "I" in character form. But from my code above, it show decimal 73(decimal of char "I").

    How can i make it to show "I" rather than showing 73?

    Thanks in advance. Sorry for my bad English and Explanation.
    If you try to append an integer to a string, it will try to treat it as a number.

    Cast the result of your math to a char before you append it to the string.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 06-16-2011, 11:59 AM
  2. Replies: 2
    Last Post: 09-12-2010, 09:15 AM
  3. Using OpenGL on Windows Form Application in Visual C++
    By yalcin in forum C++ Programming
    Replies: 2
    Last Post: 08-31-2009, 09:53 AM
  4. How do I display char 2darray in string form?
    By Mathsniper in forum C Programming
    Replies: 3
    Last Post: 12-06-2006, 01:52 PM
  5. Replies: 10
    Last Post: 08-17-2005, 11:17 PM

Tags for this Thread