Created
December 7, 2010 11:48
-
-
Save johnhmj/731710 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
#include <stdio.h> | |
#include <stdlib.h> | |
#define BUFFERSIZE 1024 | |
// | |
int main(int argc, char* argv[]) | |
{ | |
char* ptr = NULL; | |
char* pReader = NULL; | |
int i = 0, counter = 0; | |
// 動態配置記憶體 | |
ptr = (char*) malloc(BUFFERSIZE * sizeof(char)); | |
printf("Input a string: "), gets(ptr); | |
pReader = ptr; | |
for (; *(pReader + i) != NULL; i ++) | |
{ | |
if ( *(pReader + i) != 0x20 ) | |
{ | |
counter ++; | |
} | |
} | |
// 釋放記憶體 | |
free(ptr); | |
pReader = NULL; | |
// 顯示字數 | |
printf("Letters = %d\n", counter); | |
system("PAUSE"); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment