Moon Light Box

Less is More

C - How to Get the Greatest Common Divisor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a, b, temp;

    while(scanf("%d %d", &a, &b) == 2)
    {
        while(a%b)
        {
            temp = a;
            a = b;
            b = temp % b;
        }

        printf("%d\n",b);
    }
    system("PAUSE");
    return 0;
}

C - How to Reverse String?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <string.h>

void reverse(char* str)
{
    int i, j;
    char c;
    for(i = 0, j = strlen(str)-1; i<j; ++i, --j)
        c = str[i], str[i] = str[j], str[j] = c;
}

int main()
{
    char str[] = "ABCDE";
    reverse(str);
    puts(str);
    return 0;
}

C - How to Delete Space of String?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>

void delete_space(char *s1, char *s2)
{
    while(*s1 != NULL)
    {
        if(!isspace(*s1))
        {
            *s2 = *s1;
            s2++;
        }
        s1++;
    }
    *s2 = '\0';
}

int main(int argc, char *argv[])
{
    char buf[80], buf1[80];

    int i;

    printf("Please input a string\n");

    gets(buf);

    delete_space(buf, buf1);

    printf("The result of delete space from string\n");

    puts(buf1);

    system("PAUSE");

    return 0;
}

C - What Is Static Function?

A static function is a function whose scope is limited to the current source file.

靜態函式只能被所屬的檔案使用,其它檔案無法呼叫。

舉例:檔案 a.c 有 static functionA, 但檔案 b.c 無法呼叫 functionA 使用。

要注意的是 C++ 和 Java 的靜態函式功用和靜態變數相同。

How to Install Octopress Blog With Github?

之前陸陸續續用過倒掉的無名、Pixnet 和 Blogger,

這些 Blog 的編輯排版非常麻煩,尤其是要貼 Code 的時候…WTF

所以後來有一大段時間沒在寫,但隨著年紀增長開始健忘XD

因此決定找一個好用的 Blog 來防呆…

找了許久終於找到好吃的 Octopress,

Markdown 語法解決了我最討厭的排版問題,

還可以用 Vim + Git 來編輯和發布文章,

整個就是超級符合我這個懶人的 Style。

不過網路上的安裝教學文章大多是 2012 年左右的,

而我在安裝過程中也遇到些問題折騰了不少時間,

為了不再重蹈覆轍,所以通通記錄下來。