Lec30 - Computer Programming I TA C162 Today's Agenda...

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

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 03 Apr 2007 Today’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
2 Computer Programming I TA C162 . 03 Apr 2007 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: char str[30]; char line[80];
Background image of page 2
3 Computer Programming I TA C162 . 03 Apr 2007 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
4 Computer Programming I TA C162 . 03 Apr 2007 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
5 Computer Programming I TA C162 . 03 Apr 2007 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 17

Lec30 - Computer Programming I TA C162 Today's Agenda...

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

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