Docsity

String Handling and Manipulation in C: Functions and Examples, Slides of Computer Programming

Partial preview of the text

Download String Handling and Manipulation in C: Functions and Examples and more Slides Computer Programming in PDF only on Docsity!

Introduction to Programming

Lecture 17

String Handling

Character

ASCII

Example 1

#include<iostream.h>

main ( )

int i ;
char c ;
for( i = 0; i < 256 ; i ++ )
c = i ;
cout << i << “\t” << c <<endl ;

ctype Functions int isdigit ( int c ) int isalpha ( int c ) int isalnum ( int c ) int isxdigit ( int c ) int islower ( int c ) int isupper ( int c ) int tolower ( int c ) int toupper ( int c ) int isspace ( int c ) int iscntrl ( int c ) int ispunct ( int c ) int isprint ( int c ) int isgraph ( int c )

isalpha ( ) Function int isalpha ( int c ) ;

isalnum ( ) Function int isalnum ( int c ) ;

isupper ( ) Function int isupper ( int c ) ;

tolower ( ) Function int tolower ( int c ) ;

getchar ( ) ;

cout << “Please enter a character string then press enter”; while ( ( c = getchar ( ) ) != ‘\n’ ) { if ( islower ( c ) ) lc ++ ; else if ( isupper ( c ) ) uc ++ ; else if (isdigit ( c ) ) dig ++; else if ( isspace ( c ) ) ws ++ ; else if ( ispunct ( c ) ) pun ++ ; else oth ++ ; }

atoi ( ) Function char str [ ] ; int age ; age = atoi ( str ) ;

atof ( ) Function