C语言字符串学习笔记之--判断字符串的长度


 1 // 判断字符串的长度.cpp : Defines the entry point for the console application.  2 //  3 
 4 #include "stdafx.h"
 5 #include <stdio.h>
 6 #include <stdlib.h>
 7 
 8 
 9 int strlength(char *pstr) 10 
11 { 12     int i=0; 13     //char *p=pstr;
14     if (pstr==NULL) 15  { 16         return -1; 17  } 18     else
19  { 20         while(*pstr!='\0') 21  { 22             i++; 23             pstr++; 24     
25  } 26         return i; 27         
28 
29  } 30 } 31 
32 
33 
34 int main(int argc, char* argv[]) 35 { 36 
37     char str[50]={0}; 38     //gets(str);
39 
40     scanf("%s",str); 41  puts(str); 42     printf("%d",strlength(str)); 43 
44 
45 
46 
47 
48 
49     system("pause"); 50 
51 
52     return 0; 53 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM