Conversion from int to string
-
HELLO! PLEASE HELP ME! I'm new in C/C++ programming. And i have a problem: here is the code: char ch=fgetc(filein); char s[20]=""; Now what I want is to put in string s the value that is the ord(c). Example:if c is 'a' then I want put in s value "97". This part of my code is written in ANSI/C language. How can I do this? Thank you very much!
-
HELLO! PLEASE HELP ME! I'm new in C/C++ programming. And i have a problem: here is the code: char ch=fgetc(filein); char s[20]=""; Now what I want is to put in string s the value that is the ord(c). Example:if c is 'a' then I want put in s value "97". This part of my code is written in ANSI/C language. How can I do this? Thank you very much!
I assume that ord(c) should return you the ASCII value of char c (maybe I misunderstand you). Therefore,
char c = 'a';
is equivalent to
char c = 97; // here i'm not sure about the ascii value, might not be 97
Then to get a string like "97", I would recommend using sprintf, as explained in Mike's FAQ on this link.
sprintf ( s, "%d", c );
Hope this helps. ~RaGE();
-
HELLO! PLEASE HELP ME! I'm new in C/C++ programming. And i have a problem: here is the code: char ch=fgetc(filein); char s[20]=""; Now what I want is to put in string s the value that is the ord(c). Example:if c is 'a' then I want put in s value "97". This part of my code is written in ANSI/C language. How can I do this? Thank you very much!
I am quite a beginner myself, but I think u can use pointers to do this. Something like: char *ptrs=NULL; char s[20]="a, c, d, f, l, m"; ptrs=&s[3];//pointer points le address of s[3] printf(" %d\n", s[3]);//should print the address *ptrs=63; //value of pointer is 63 printf(" %d\n", s[3]);//should print 63 I think this is not correct, but might give you ideas. :doh: THX