Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] get character using ASCII and make one string, using C

Status
Not open for further replies.

Micro Lover

Member level 2
Joined
Jul 22, 2009
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
pakistan
Activity points
1,614
hi

I have some ASCII values and some characters, now i want to get the character with given ASCII value and make a one string,

here is simple Pseudo-code

int W=65; X=67
string Y = "B" ; Z = "D"
string Result = ""

Result = chr(W) & Y & chr(X) & Z

--------------
Output
---------

Result = "ABCD"


i need help for C language, for Keil
 

The ascii value is already a character, for example the following are exactly the same

Code:
char my_array[4];

my_array[0]=65;
is the same as my_array[0]='A';

So what you want can simply be done


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
char my_array[5];
int W=65;
int X=67;
char Y = 'B';  // note the single quotes
char Z = 'D';
 
my_array[0]= (char)W; // char is only used to typecast the 16bit integer to a 8bit character, not to convert a number to a letter, if W and X are declared as char then no typecasting is needed
my_array[1]=Y;
my_array[2]=(char)X; // if you don't use the typecasting you will get warnings from the compiler, the result will still be correct
my_array[3]=Z;
my_array[4]=0; // null terminated



Alex
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top