Created
December 4, 2010 11:38
-
-
Save johnhmj/728122 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. 設計一主程式,並呼叫一個副程式StrLen()可以算出字串a[]之字元數目。(不包括 \0) | |
主程式:(1) 輸入一個字串資料a[]。(2) 呼叫StrLen(),印出字串a[]之字元數目。 | |
副程式:StrLen(),可以算出字串a[]之字元數目,並將結果傳回主程式。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Integrated Development Environment | |
// Visual C++ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define BUFFERSIZE 512 | |
unsigned int StrLen(const char* str); | |
// | |
int main(int argc, char* argv[]) | |
{ | |
char a[BUFFERSIZE]; | |
printf("Input a string: "), gets(a); | |
printf("StrLen = %u\n", StrLen(a)); | |
system("PAUSE"); | |
return (0); | |
} | |
unsigned int StrLen(const char* str) | |
{ | |
unsigned int i = 0; | |
for (; str[i] != '\0'; i ++); | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment