Lecture33 - Todays Agenda Character Arrays One dimensional...

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 . 5 Apr 2006 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 Document Right Arrow Icon
2 Computer Programming I TA C162 . 5 Apr 2006 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 . 5 Apr 2006 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[]=“BITS”; char[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 Document Right Arrow Icon
4 Computer Programming I TA C162 . 5 Apr 2006 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 . 5 Apr 2006 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 Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 17

Lecture33 - Todays Agenda Character Arrays One dimensional...

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