指针与字符串

C Primer Plus 第11章 字符串和字符串函数 11.1字符串表示和字符串I/O

空扰寡人 提交于 2019-11-30 04:50:32
当然,最基本的您已经知道了: 字符串(character string)是以空字符(\o)结尾的char数组 。因此,您所学的数组和指针就可以用在字符串上。但是由于字符串的使用非常广泛,C提供了很多专为字符串设计的函数。本章将讨论字符串的特性、声明和初始化方法、如何在程序中输入输出字符串,以及字符串的操作。 程序清单11.1 string.c程序 //string.c --使用字符串与用户交互 #include <stdio.h> #define MSG "You must have many talents. Tell me some. " #define LIM 5 #define LINELEN 81 //最大字符串长度加1 int main(void) { char name[LINELEN]; char talents[LINELEN]; int i; const char m1[40]="Limit yourself to one line's worth. "; //初始化一个大小已确定的char数组 const char m2[]="If you can't think of anything,fake it. ";//让编译器计算数组大小 const char *m3="\nEnough about me - what's your name? "; /