Professional Documents
Culture Documents
Lesson 11 - String - VVTU
Lesson 11 - String - VVTU
Character Strings
TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
Presenter: Dr. Vu Van Thieu They are assigned values with a pair of double quotes:
Department of Computer Science Example: char arraychar[6] = "abcde" ;
School of Information and Communication Technology
Hanoi University of Science and Technology
1 2
This means that the value of a string is the char uni [ ] = “HUST" ;
address of it's first character. or
char *uni = “HUST" ;
Address in string: or
char university[5] = “HUST" ; char uni [5] = {‘H', ‘U', ‘S', ‘T', '\0'} ;
university[0] = ‘H’
NOTE: Allowance must always be made for the
university[2] = ‘S’ terminating null character.
3 4
#include <stdio.h>
#include <stdio.h>
/* The following are function prototypes for some
of the String I/O and Handling Library Routines */ /* Print character stored in character variable c
*/
/* Input next character as an integer */
int putchar (int c) ;
int getchar (void) ;
/* Input string into array s until newline */ /* Print character string s followed by \n */
char *gets (char *s) ; // Do not use, ever int puts (const char *s) ;
5 6
1
Nhập môn CNTT&TT 2016
7 8
Function Returns
9 10
11 12
2
Nhập môn CNTT&TT 2016
13 14
Summary
What is string
How to declare and initialize a string
Input/Output a string
Character functions
String functions
15