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 }