LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2012, 12:05 AM   #1
chinabenjamin66
Member
 
Registered: Mar 2012
Location: Shenzhen Chian
Posts: 73

Rep: Reputation: Disabled
Which function in C can return the integer ordinal of a character?


Hello friends

I am a beginner of C programing, I want to know Which function in C can return the integer ordinal of a character? and which function in C can return a charater with ordinal i; 0<=i<256?

I know ord()and chr() in python can do this, but don't know which function in C?

Can anyone give any clue?

Best Regards.
 
Old 12-17-2012, 01:53 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
A character in C is the ordinal. char is an integral type.

Code:
/* You can use both ways to assign a character */
char c1 = 65;
char c2 = 'B';

/* You can print a character both ways, too */
printf("%c\n", c1);
printf("%i\n", c2)
 
Old 12-17-2012, 08:47 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There is really no such concept in C. There are different ways of representing the same data type, but the underlying data is still the same. The example posted by millgates demonstrates this nicely.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C function not returning an integer after comparing it to a char Reverse Logic Programming 21 01-27-2010 02:12 AM
To know the function on checking whether a character is ascii or unicode character. murugesan Programming 2 01-23-2009 01:07 PM
function won ' t return character array word Linh Programming 1 07-31-2003 06:11 PM
C can 't return a character array Linh Programming 5 06-18-2003 04:58 AM
Cannot pass and return a character array Linh Programming 1 06-12-2003 04:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration