Skip to content

Instantly share code, notes, and snippets.

@johnhmj
Created December 7, 2010 11:48
Show Gist options
  • Save johnhmj/731710 to your computer and use it in GitHub Desktop.
Save johnhmj/731710 to your computer and use it in GitHub Desktop.
#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