The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 integer to ascii character
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 11/15/2004 :  04:46:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5 SR5
Operating System: Win2000

Hi,

Is there a way of converting an integer to the actual ascii character eg loop 1 to 26 to output a,b...z etc. with Origin C?

Thanks,

cheers,

Pete

rlewis

Canada
253 Posts

Posted - 11/15/2004 :  10:20:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try the following ...


void CharToInt()
{
vector<byte> Characters={'A','B','C','D','a','b','c','d'};
vector<int> Numbers;
Numbers=Characters;
string strOutPut;
int MyInt;
for (int i=0; i<8; i++)
{
char MyChar[1]=Characters[i];
MyInt=Numbers[i];
strOutPut.Format("%s,%d",MyChar, MyInt);
out_str(strOutPut);
}
}
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 11/15/2004 :  10:48:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the assist Ruthven.
Probably a more useful & flexible approach for my purposes anyway.

Cheers,

pete

Go to Top of Page

eparent

118 Posts

Posted - 11/15/2004 :  10:56:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Peter here are two macros that will be more efficient.
I have also included two functions that show how to use the macros.


#define GET_UPPER_CASE_LETTER(n) ((char)((n) - 1 + 'A'))
#define GET_LOWER_CASE_LETTER(n) ((char)((n) - 1 + 'a'))
void OutputUpperCaseLetters()
{
for( int n = 1; n <= 26; n++ )
printf("%c\n", GET_UPPER_CASE_LETTER(n));
}
void OutputLowerCaseLetters()
{
for( int n = 1; n <= 26; n++ )
printf("%c\n", GET_LOWER_CASE_LETTER(n));
}



Go to Top of Page

peter.cook

UK
356 Posts

Posted - 11/16/2004 :  06:53:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Thanks for this - it is slick.

Both methods will have their uses in other apps.

Cheers,

Pete

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000