首页 > 其他 > 详细

用指针打印字符串长度(指针 & fgets函数)

时间:2020-04-05 20:08:10      阅读:59      评论:0      收藏:0      [点我收藏+]
 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #define MAX 1024
 5 
 6 int main(){
 7  //用指针打印字符串长度
 8  char str[MAX];
 9  char *target = str;
10  int length = 0;
11 
12  printf("请输入一个字符串:");
13  fgets(str, MAX, stdin);
14 
15 //fgets(字符数组,数组长度,stdin), stdin是标准输入
16 
17  while (*(target++) != \0){
18   length++;
19  }
20  printf("您输入了%d个字符\n", length - 1);
21  //由于fgets函数会读取到回车,因此length - 1
22  
23  system("pause");
24  return 0;
25 }

 

用指针打印字符串长度(指针 & fgets函数)

原文:https://www.cnblogs.com/Leafbud/p/12638562.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!