C语言编程练习11章.docVIP

  • 8
  • 0
  • 约 16页
  • 2017-06-12 发布于北京
  • 举报
第11章 字符串和字符串函数 编程练习 1.设计并测试一个函数,可以从输入读取n个字符(包括空格、制表符和换行符),把结果存储在一个数组中,这个数组的地址通过参数来传递。 #include stdio.h void input(char *p, int n); int main(void) { char a[81]; int n; puts(input the char number of your string:); scanf(%d,n); getchar(); //滤去回车 puts(input your string:); input(a,n); puts(a); return 0; } void input(char *p, int n) { int i; for (i=0;in;i++) *(p+i) = getchar(); *(p+i) = \0; } 2.修改并测试练习1中的函数,使得可以在n个字符后,或第一个空格、制表符、换行符后停止读取输入,由上述情况中最先被满足的那个终止读取(不能用scanf()函数)。 #include stdio.h #include ctype.h void input(char *p, int n); int main(void) { char a[81]

文档评论(0)

1亿VIP精品文档

相关文档