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