cp_1_lect_39 - String Input/Output continued Using putchar...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
5/10/10 Using putchar ( ) and puts ( ): char ch = ‘A’; putchar (ch); char name[5] = “BITS”; String Input/Output continued… char ch = ‘A’; printf (“%c”, ch); char line [30]; gets (line); puts (line);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 Arithmetic on Characters Whenever a character constant or variable is used in an expression, it is automatically converted to an integer value. x = ‘a’; printf (“%d\n”, x); arithmetic x = ‘a’ – 1; Output: 97 Output: 96
Background image of page 2
5/10/10 Example of atoi ( ): number = “2007”; year = atoi (number); /* year is an integer variable*/ To print a to z and A to Z in decimal and char form: Arithmetic on Characters
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 String Manipulations continued… String concatenate
Background image of page 4
5/10/10 String Manipulations continued… A Char in a string
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 String Length : n = strlen (str); Returns number of characters String Manipulations continued… C C O A N T A N E O I T N \0 s1 p1 = strstr (s1, “CAT”); A String in a String Many more: strlwr, strupr strcmpi, strdup, strset,strrev etc.
Background image of page 6
5/10/10 String Manipulations: Without using string.h Length of a string: ( without using strlen ( ) ) int i = 0; char text[100]; char c; while ( ( c = getchar() ) != ‘\n’ && i < 99 ) {
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/07/2010 for the course CS&IS TA C162 taught by Professor Kavitha during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 13

cp_1_lect_39 - String Input/Output continued Using putchar...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online