+ All Categories
Home > Documents > Characters and Strings

Characters and Strings

Date post: 15-Feb-2016
Category:
Upload: arav
View: 37 times
Download: 0 times
Share this document with a friend
Description:
Characters and Strings. Character and String definitions, algorithms, library functions. Character and String Processing. A common programming issue involves manipulation of text, usually referred to as string, or text, processing To achieve solutions typically requires capabilities to: - PowerPoint PPT Presentation
Popular Tags:

of 31

Click here to load reader

Transcript

Array Data Structures & Algorithms

Character and String definitions, algorithms, library functionsCharacters and Strings1Character and String ProcessingA common programming issue involves manipulation of text, usually referred to as string, or text, processingTo achieve solutions typically requires capabilities to:perform input and output of characters and stringsquery what a single character is, or is notdetermine if a character, a substring, or any of a set of characters is included, or not, in a stringdetermine the attributes of a character (eg. upper versus lower case) or string (eg. length)convert between character string and machine representations of different data typesbreak large strings into smaller substrings recognized by tokensjoin substrings into larger strings (catenation)2Characters and Strings in CThe concept of a string refers to a sequence of items. The sequence, or string, may contain zero or more elements, and a delimiter that denotes the end (termination) of the string.A string of characters, in computer science terms, usually refers to a vector, or list, of char valuesASCII is commonly used UniCode is anotherIn the C language, the special delimiter character \0 (called character null) is recognized by the compiler and assigned a specific integer valueStrings of bits (or other encoded symbols) provides abstraction possibilities for more general strings.3FundamentalsDefining a string containerExample: #define STRLEN 256 char strName [ STRLEN ] ; Example: char strName [ ] ; char * strPtr ;

InitializationExample: char strName1 [ ] = My name is Bob! ; const char * strStatic = String that cannot be changed! ; char strName2 [ ] = { H, e, l, l, o, \0 } ;Example: char strName [ 50 ] ; int k ; for( k=0; k0 if c is any valid control character data (including \n, \b, \r, \a etc); otherwise 0int ispunct( int c );Returns >0 if c is any valid, printable punctuation character data (including ,, ., ;, : etc.); otherwise 0int isprint( int c );Returns >0 if c is any valid, printable character data; otherwise 0int isgraph( int c );Returns >0 if c is any valid character data representing a graphical symbol (such as , #, $ etc, and including extensions to ASCII); otherwise 0Example: Counting charactersProblem: Determine the frequencies of occurrence for each alphabetic character (ignoring case) in a text file.Solution: #include #include int main ( ) { int N=0, K, C[26] ; double F[26] ; char Ch ; for( K=0; K


Recommended