标签:函数 targe return pre 字符串 ret warnings stdin include
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 }
标签:函数 targe return pre 字符串 ret warnings stdin include
原文地址:https://www.cnblogs.com/Leafbud/p/12638562.html