function that accepts 2 parameters an unsigened char and a pointer to character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mostafaAlderea
    New Member
    • Jan 2010
    • 3

    function that accepts 2 parameters an unsigened char and a pointer to character

    the function converts the first parameter into a string containing the hexadecimal equivalent of the number
  • mostafaAlderea
    New Member
    • Jan 2010
    • 3

    #2
    iam a student and i am beginner in programming but i can not understand how to change a char into a string

    Comment

    • mostafaAlderea
      New Member
      • Jan 2010
      • 3

      #3
      and also how the string containing the hexadecimal equivalent of the number

      what i know is that strings is an arrau of character

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        Code:
        //A string is a series of characters.
        string s="This is my hex number - 0xff";
        cout<<s; //prints--> This is my hex number - 0xff
        cout<<dec<<0xff; // prints 255
        /*Or you can use a container like an array 
        so that each array element from 0 up contains 
        each character from the first onwards.*/
        char a[]={'0','x',1,2,3,4,'/0'};  //initialize a 7 element 
                                   //array with a hex number
        for(int i=0;i<6;i++) //traverse array and print its individual
        // elements 
        cout<<a[i];//prints 0x1234
        cout<<dec<<0x1234;   // prints 4660
        //hope this helps.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          I see.....you wish to write a function which converts an integer (in hexadecimal format) into a string?.....yes ?
          If so consider the following.
          int hex_num=0;
          cout<<"enter an integer in hex format";
          cin>>hex_num; //say 0x1234 is entered

          string convert_hex_to_ string(hex_num) //conversion function of type string
          {
          string s=hex_num; //now s contains the string " 0x1234"
          return s;
          }
          cout<<s;//prints 0x1234
          Is that what you are trying to do.....or is it something else entirely?

          Comment

          Working...