473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Jan 12 '10 #1
4 1537
iam a student and i am beginner in programming but i can not understand how to change a char into a string
Jan 12 '10 #2
and also how the string containing the hexadecimal equivalent of the number

what i know is that strings is an arrau of character
Jan 12 '10 #3
whodgson
542 512MB
Expand|Select|Wrap|Line Numbers
  1. //A string is a series of characters.
  2. string s="This is my hex number - 0xff";
  3. cout<<s; //prints--> This is my hex number - 0xff
  4. cout<<dec<<0xff; // prints 255
  5. /*Or you can use a container like an array 
  6. so that each array element from 0 up contains 
  7. each character from the first onwards.*/
  8. char a[]={'0','x',1,2,3,4,'/0'};  //initialize a 7 element 
  9.                            //array with a hex number
  10. for(int i=0;i<6;i++) //traverse array and print its individual
  11. // elements 
  12. cout<<a[i];//prints 0x1234
  13. cout<<dec<<0x1234;   // prints 4660
  14. //hope this helps.
Jan 12 '10 #4
whodgson
542 512MB
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?
Jan 14 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bryan Parkoff | last post by:
Do C/C++ Compiler allow function to contain more than 8 parameters? I checked MS Visual C++ 6.0 that it can only limit 8 parameters, but most C/C++ Compiler can limit maximum 256 parameters. Can...
7
by: Computer Whizz | last post by:
Hi, I was just wondering if someone would like to comment on these two issues. I had a 15 minute wander around some sites and was curious about loading files (plain ASCII I think will do for a...
13
by: Eirik WS | last post by:
I have a function(whose code I have stolen from one of you in comp.lang.c): void myStringClean(char *String) { char *pointer; if((pointer = strchr(String, '\n')) != NULL) { *pointer = '\0'; }...
64
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
9
by: weirdwoolly | last post by:
Hopefully someone will be able to help. I have written a stored procedure in C++ called from a Java test harness to validate the graphic data types in C++ and their use. I have declared the...
6
by: mdh | last post by:
I guess pointers just take time!!! This is exercise 5-13, peripherally. The function accepts a command line argument of -n. So, given int main ( int argc, char *argv)
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.