string - ComputerProgrammingITAC162. Tonights Agenda...

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

View Full Document Right Arrow Icon
Computer Programming I TA C162 . 03 Apr 2007 1 Tonight’s Agenda Character Arrays One dimensional Arrays Strings Declaration Initialization Printing Reading Examples Character Manipulation in strings String Manipulation
Background image of page 1

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

View Full DocumentRight Arrow Icon
Computer Programming I TA C162 . 03 Apr 2007 2 Strings  Strings in C are represented by arrays of characters  End of the string is marked with a special character NUL.  The corresponding escape sequence character is \0.  C does not have string data type. Declaration of strings:lauda char str[30]; char line[80];
Background image of page 2
Computer Programming I TA C162 . 03 Apr 2007 3 String Initialization: char str[9] = “I like C”;                         same as char str[9]={‘I’,‘ ‘,’l’,‘i’,’k’,’e’,‘ ‘,’C’,’\0’}; Q. Is there any difference between following Initialization? char str[]=“BITS”; char str[4]= “BITS”; Ans : Yes, in second declaration there is no null character
Background image of page 3

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

View Full DocumentRight Arrow Icon
Computer Programming I TA C162 . 03 Apr 2007 4 Printing Strings char text[]=“C Programming”; printf("%s\n",text); printf("%10.5s\n",text); printf("%-10.5s",text); Output??? C Programming C Pro C Pro
Background image of page 4
Computer Programming I TA C162 . 03 Apr 2007 5 Reading a String (2-1)   Using scanf() char text[30]; printf(“Enter a string: ”); scanf(“%s”,text); printf(“The string is : %s”,text); Sample output: Enter a string: hello The string is: hello ----------------------------------------- Enter a string: hello how are you The string is: hello Note: scanf() takes string without blank space
Background image of page 5

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

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

This note was uploaded on 05/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 19

string - ComputerProgrammingITAC162. Tonights Agenda...

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

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