INDEX
[C]C言語学習メモ
1  NI-Lab.  2003/06/20(Fri) 13:44
[C]C言語学習メモ

やっぱりポインタで躓く……10年前から、同じだ。
2  NI-Lab.  2003/06/20(Fri) 13:44
/*
* ポインタ学習用swap関数。
*
* 実行結果:
* >swap
* 2, 5
* 5, 2
*/

#include <stdio.h>

void swap(int *x, int *y);

int main(int argc, char *argv[]){

int a;
int b;

a = 2;
b = 5;
printf("%d, %d\n", a, b);
swap(&a, &b);
printf("%d, %d\n", a, b);

return 0;
}

void swap(int *x, int *y){

int temp;
temp = *x;
*x = *y;
*y = temp;
}


3  NI-Lab.  2003/06/20(Fri) 13:45
/*
* 構造体を入れ替える。
* 実行結果:
* >swapnode
* swapNodeTest
* 0=2, 1=5
* 1=5, 0=2
*/

#include <stdio.h>

struct node{
int id;
int value;
};

typedef struct node Node;

void swapNode(Node *x, Node *y);

int main(int argc, char *argv[]){

Node nodeA;
Node nodeB;

nodeA.id = 0;
nodeA.value = 2;
nodeB.id = 1;
nodeB.value = 5;

printf("swapNodeTest\n");
printf("%d=%d, %d=%d\n", nodeA.id, nodeA.value, nodeB.id, nodeB.value);
swapNode(&nodeA, &nodeB); // nodeA と nodeB を入れ替える
printf("%d=%d, %d=%d\n", nodeA.id, nodeA.value, nodeB.id, nodeB.value);

return 0;
}

void swapNode(Node *x, Node *y){

Node temp;
temp = *x;
*x = *y;
*y = temp;
}


4  NI-Lab.  2003/06/20(Fri) 13:46
pre忘れ。もう一度。

/*
* 構造体を入れ替える。
* 実行結果:
* >swapnode
* swapNodeTest
* 0=2, 1=5
* 1=5, 0=2
*/

#include <stdio.h>

struct node{
int id;
int value;
};

typedef struct node Node;

void swapNode(Node *x, Node *y);

int main(int argc, char *argv[]){

Node nodeA;
Node nodeB;

nodeA.id = 0;
nodeA.value = 2;
nodeB.id = 1;
nodeB.value = 5;

printf("swapNodeTest\n");
printf("%d=%d, %d=%d\n", nodeA.id, nodeA.value, nodeB.id, nodeB.value);
swapNode(&nodeA, &nodeB); // nodeA と nodeB を入れ替える
printf("%d=%d, %d=%d\n", nodeA.id, nodeA.value, nodeB.id, nodeB.value);

return 0;
}

void swapNode(Node *x, Node *y){

Node temp;
temp = *x;
*x = *y;
*y = temp;
}


5  NI-Lab.  2003/06/20(Fri) 13:46
/*
* 構造体の中身を入れ替える。
* 実行結果:
* >swapnode
* swapValueTest
* 0=2, 1=5
* 0=5, 1=2
*/
#include <stdio.h>

struct node{
int id;
int value;
};

typedef struct node Node;

void swap(int *x, int *y);

int main(int argc, char *argv[]){

Node nodeA;
Node nodeB;

nodeA.id = 0;
nodeA.value = 2;
nodeB.id = 1;
nodeB.value = 5;

printf("swapValueTest\n");
printf("%d=%d, %d=%d\n", nodeA.id, nodeA.value, nodeB.id, nodeB.value);
swap(&(nodeA.value), &(nodeB.value)); // nodeA.value と nodeB.value を入れ替える
printf("%d=%d, %d=%d\n", nodeA.id, nodeA.value, nodeB.id, nodeB.value);

return 0;
}

void swap(int *x, int *y){

int temp;
temp = *x;
*x = *y;
*y = temp;
}


6  NI-Lab.  2003/06/20(Fri) 13:57
/*
* ポインタ操作に使う * と &
* 実行結果:
* >pointertest
* a=12
* *pa=12
* pa=1245064
* &a=1245064
*/

#include <stdio.h>

int main(int argc, char *argv[]){

int a;
int *pa; // aへのポインタ

a = 12;
pa = &a;

printf("a=%d\n", a);
printf("*pa=%d\n", *pa);
printf("pa=%d\n", pa);
printf("&a=%d\n", &a);

return 0;
}

7  NI-Lab.  2003/06/20(Fri) 14:04
/*
* malloctest.c
* mallocによるメモリの動的確保。
* a は静的にメモリが確保されている。
* b は動的にメモリが確保されている(実際にはbを宣言しない)。
*
* 実行結果:
* >malloctest
* a=12
* *pa=12
* pa=1245064
* &a=1245064
* *pb=23
* pb=8857820
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){

// a
int a;
int *pa; // aへのポインタ

// b
int *pb;

// a
pa = &a;
a = 12;

// b
pb = malloc(sizeof(int));
*pb = 23;

// a
printf("a=%d\n", a);
printf("*pa=%d\n", *pa);
printf("pa=%d\n", pa);
printf("&a=%d\n", &a);

// b
printf("*pb=%d\n", *pb);
printf("pb=%d\n", pb);

free(pb);

return 0;
}


8  NI-Lab.  2003/06/20(Fri) 20:31
/*
* ポインタのポインタを利用して変数の内容を参照する。
* 参考: http://anshun1.fjct.fit.ac.jp/kougi/kiso3_05/Slide06.html
*/

#include<stdio.h>

int main(int argc, char *argv[]){

int a;
int *p;
int **q;

a = 50;
p = &a;
q = &p;

printf("a=%d, *p=%d, **q=%d\n", a, *p, **q);

return 0;
}


9  NI-Lab.  2003/06/22(Sun) 12:48
/*
* ポインタのポインタを関数へ渡して、
* 参照している値を変更し、
* 参照しているポインタの値を変更する。
*/
#include <stdio.h>
#include <stdlib.h>

void setValue(int **target, int value){
**target = value;
}

void setPointer(int **target, int value){

int *temp;
temp = (int *)malloc(sizeof(int));
*temp = value;
*target = temp;

printf("setPointer内\n");
printf("value=%d\n", value);
printf("target=%d\n", target);
printf("*target=%d\n", *target);
printf("**target=%d\n", **target);
printf("temp=%d\n", temp);
printf("*temp=%d\n", *temp);
}

int main(){

int a;
int *pa;
int **ppa;

a = 3;
pa = &a;
ppa = &pa;

printf("初期設定値\n");
printf("a=%d\n", a);
printf("pa=%d\n", pa);
printf("*pa=%d\n", *pa);
printf("ppa=%d\n", ppa);
printf("*ppa=%d\n", *ppa);
printf("**ppa=%d\n", **ppa);

setValue(ppa, 5);

printf("setValue後\n");
printf("a=%d\n", a);
printf("pa=%d\n", pa);
printf("*pa=%d\n", *pa);
printf("ppa=%d\n", ppa);
printf("*ppa=%d\n", *ppa);
printf("**ppa=%d\n", **ppa);

setPointer(ppa, 8);

printf("setPointer後\n");
printf("a=%d\n", a);
printf("pa=%d\n", pa);
printf("*pa=%d\n", *pa);
printf("ppa=%d\n", ppa);
printf("*ppa=%d\n", *ppa);
printf("**ppa=%d\n", **ppa);

return 0;
}

10  NI-Lab.  2003/06/22(Sun) 12:48
>>9 の詳細コメント

/*
* ポインタのポインタを関数へ渡して、
* 参照している値を変更し、
* 参照しているポインタの値を変更する。
*
* **ppa の値が 3 -> 5 -> 8 と変化していく。
* 3 ---(参照している値を変更)---> 5
* 5 ---(参照しているポインタを変更)---> 8
*
* ポインタ変数を交換することで *ppa の値(アドレス)を変更している。
* この実行例では *ppa が 1245064 -> 8857812 となる。
*
* ----------------- 概念図? -----------------
* Pn:ポインタ
* Vn:変数
*
* 初期設定:
* P1 -> P2 -> V1
* P2=1245064
* V1=3
*
* setValue後:
* P1 -> P2 -> V1
* P2=1245064
* V1=5
*
* setPointer後:
* P1 -> P2 -> V2
* P2=8857812
* V2=8
* V2はmallocで動的にメモリを確保している。
* --------------------------------------------
*
* ---------- 実行結果 ----------
* 初期設定値
* a=3
* pa=1245064
* *pa=3
* ppa=1245060
* *ppa=1245064
* **ppa=3
* setValue後
* a=5
* pa=1245064
* *pa=5
* ppa=1245060
* *ppa=1245064
* **ppa=5
* setPointer内
* value=8
* target=1245060
* *target=8857812
* **target=8
* temp=8857812
* *temp=8
* setPointer後
* a=5
* pa=8857812
* *pa=8
* ppa=1245060
* *ppa=8857812
* **ppa=8
* ------------------------------
*/

11  NI-Lab.  2003/06/22(Sun) 12:51
>>10

>ポインタ変数を交換することで *ppa の値(アドレス)を変更している。

うぅ、なんかわかりづらい。
概念図でいうと……P2の値を変更している、ということ。
12  NI-Lab.  2003/06/22(Sun) 15:17
/*
* 連結リストの操作。
* (親子)Deitel著「C言語プログラミング」の
* リスト12.1のプログラムっぽいものの一部を、
* 自分なりに解釈してつくってみた。
* 「二重間接参照」なるものの説明がわかりにくいなぁ、この本。
* ----------
* 実行結果:
* 1
* 2
* 3
* 4
* 5
* 10
* 100
* 1000
* 10000
* 100000
* 100000
* ----------
*/

#include <stdio.h>
#include <stdlib.h>

#define FALSE 0
#define TRUE !FALSE
#define boolean int

//#define debug(x) fputs(x, stderr)
#define debug(x)

struct node{
int value;
struct node *next;
};

typedef struct node Node;

void print(Node *list);

boolean insert(Node **list, int value);

int main(int argc, int *argv[]){

Node *pList;
Node **ppList;

pList = NULL;
ppList = &pList;

insert(ppList, 1);
insert(ppList, 3);
insert(ppList, 5);
insert(ppList, 4);
insert(ppList, 2);
insert(ppList, 10);
insert(ppList, 100);
insert(ppList, 100000);
insert(ppList, 1000);
insert(ppList, 10000);
insert(ppList, 100000);

print(pList);

return 0;
}

void print(Node *list){

Node *pCurrentNode;
pCurrentNode = list;

while(pCurrentNode != NULL){
printf("%d\n", pCurrentNode->value);
pCurrentNode = pCurrentNode->next;
}

}

13  NI-Lab.  2003/06/22(Sun) 15:17
>>12の続き

/**
* 要素をリストへ追加します。
* @param list リストの最小ノード
* @param value 追加する値
*/
boolean insert(Node **list, int value){

Node *pNewNode; // 実体のために、動的にメモリを確保する
Node *pCurrentNode; // 実体はすでにある or NULL
Node *pPreviousNode; // 実体はすでにある or NULL

pNewNode = (Node *)malloc(sizeof(Node));
pCurrentNode = NULL;
pPreviousNode = NULL;

if (pNewNode != NULL){

pNewNode->value = value;
pNewNode->next = NULL;

pCurrentNode = *list;
pPreviousNode = NULL;

while(pCurrentNode != NULL && value > pCurrentNode->value){
debug("while loop\n");
pPreviousNode = pCurrentNode;
pCurrentNode = pCurrentNode->next;
}

if (pPreviousNode == NULL){
debug("pPreviousNode is NULL\n");
pNewNode->next = pCurrentNode;
*list = pNewNode;
}else{
debug("pPreviousNode is not NULL\n");
pPreviousNode->next = pNewNode;
pNewNode->next = pCurrentNode;
}

}else{
debug("*** malloc failed! ***\n");
return FALSE;
}

return TRUE;
}


14  NI-Lab.  2003/06/23(Mon) 23:29
/*
* スタックの実装。
*
* 実行結果:
* ------------------------
* >stack
* No node is in stack.pop0
* No node is in stack.pop0
* No node is in stack.pop0
* push 1
* pop1
* push 3
* push 5
* pop5
* pop3
* push 7
* push 9
* pop9
* pop7
* No node is in stack.pop0
* No node is in stack.pop0
* No node is in stack.pop0
* ------------------------
*/

#include <stdio.h>
#include <stdlib.h>

struct node{
int value;
struct node *next;
};

typedef struct node Node;

void push(Node **list, int value){

Node* pNewNode;
pNewNode = (Node *)malloc(sizeof(Node));

pNewNode->next = *list;
pNewNode->value = value;

*list = pNewNode;

printf("push %d\n", value);
}

int pop(Node **list){

Node *target;
int value;

if (*list == NULL){
fputs("No node is in stack.", stderr);
return 0;
}

target = *list;

value = target->value;
*list = target->next;

free(target);

return value;
}

int main(){

Node *pNode;
Node **ppNode;

pNode = NULL;
ppNode = &pNode;

printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));

push(ppNode, 1);
printf("pop%d\n", pop(ppNode));
push(ppNode, 3);
push(ppNode, 5);
printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));
push(ppNode, 7);
push(ppNode, 9);

printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));
printf("pop%d\n", pop(ppNode));

return 0;
}


15  NI-Lab.  2003/06/25(Wed) 12:41
/*
* 引数を表示する。
*/
#include <stdio.h>

int main(int argc, char *argv[]){

int i;
printf("argc=%d\n", argc);
for (i=0; i<argc; i++){
printf("argv[%d]=%s\n", i, argv[i]);
}

return 0;
}

16  NI-Lab.  2003/06/25(Wed) 17:17
/*
* strpos and strrpos
* この関数は、ANSIでは存在しない?
*/
#include <string.h>
#include <stdio.h>

/**
* 引数s内で引数cが最初に出現する配列のインデックスを返します。
*/
int strpos(char *s, char c);

/**
* 引数s内で引数cが最後に出現する配列のインデックスを返します。
*/
int strrpos(char *s, char c);

int main(){

char str[] = "abcdeabcde";
char t1 = 'a';
char t2 = 'e';
printf("%d\n", strpos(str, t1));
printf("%d\n", strpos(str, t2));
printf("%d\n", strrpos(str, t1));
printf("%d\n", strrpos(str, t2));
return 0;
}

int strpos(char *s, char c){

char temp;
int pos;

pos = 0;

while(*s != '\0'){

temp = *s;

if (temp == c){
return pos;
}

s++;
pos++;
}

return -1;
}

int strrpos(char *s, char c){

char temp;
int pos;
int size;

for (pos=strlen(s)-1; pos >= 0; pos--){

temp = s[pos];

if (temp == c){
return pos;
}
}

return -1;
}

17  NI-Lab.  2003/06/26(Thu) 00:24
/*
* continueが while, for, do/while 構造の中で実行されると、
* 制御構造の残りの部分をスキップして、次の反復に入る。
* 単純なブロックは、この動作に関係ない。
*/
#include <stdio.h>

int main(){

int a;
int b;

a = 0;
b = 10;

while(a < b){

{ /* ブロックここから */
printf("a=%d\n", a);

if(a == 5){
a++;
continue;
}

} /* ブロックここまで */

printf("loop end\n");
a++;
}

return 0;
}


18  NI-Lab.  2003/11/03(Mon) 12:47
文字列定数表現。

const char *const LABEL_TEXT = "Hello, It's me.";
19  Dream  2004/12/04(Sat) 09:41
// This program is example of function for Array


#include <iostream.h>

char Display();
void Display2( char *argv );

int main( int argc , char *argv ) // int argc & char *argv are strictly requried for Main function only.
{
if ( argc <= 1 ) // This is for 引数 error
{
return 1;
}
Display();
Display2( *argv );
return 0;

}// Finished Main

char Display()
{
char *word = 0;

cout << "\t *********************" << endl;
cout << "\t This is TEST program." << endl;
cout << "\t *********************" << endl;
cout << "\n\t Please enter one character." << endl;

cin >> word;

return *word;

}// Diplay Finished

void Display2( char *w )
{
cout << "You have entered" << endl;
cout << w << endl;
}

最近C++を勉強をし始めたばかりなので、何処が間違えてるのかが、
分からないので、誰か分かる方いいアドバイスもらえますか?
20  NI-Lab.  2004/12/13(Mon) 22:17
環境
MINGW32_NT-5.0 PC00452 1.0.10(0.46/3/2) 2004-03-15 07:17 i686 unknown
gcc version 3.2.3 (mingw special 20030504-1)

角度から座標を求めたり、座標から角度を求めたり、角度数からラジアン値を求めたり、ラジアン値から角度数を求めたり、

/*
* 角度数から諸情報を求めて出力します。
* 第一引数に指定した数値分に 360°を分割します。
* 指定なしの場合は、360°を8分割します。
*
* 出力フォーマット:
* 角度数 -> ラジアン -> (x, y) -> アークタンジェント -> 角度数
*
* 参考:
* Macromedia - FLTN : fl0189 - 角度と座標の計算 − Flash 5 の三角関数を使う
* http://www.macromedia.com/jp/support/flash/ts/documents/fl0189.html
*/

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#define PI 3.14159265358979323846

int main(int argc, char *argv[]){

int num = 8;
if(argc >= 2){
num = atoi(argv[1]);
}

int i;
for(i=0; i<num+1; i++){
double theta = (360.0 / num) * i;
double radian = theta * PI / 180.0;
double x = cos(radian);
double y = sin(radian);
double arctangent = atan2(y, x);
double theta2 = arctangent * 180.0 / PI;
if(theta2 < 0){
theta2 += 360.0;
}
printf(
"%6.2f -> % 08.6f -> (% 08.6f, % 08.6f) -> % 08.6f -> %10.6f\n",
theta, radian, x, y, arctangent, theta2);
}

return 0;
}

21  NI-Lab.  2004/12/13(Mon) 22:19
>>20 の実行結果 64分割の場合

0.00 -> 0.000000 -> ( 1.000000, 0.000000) -> 0.000000 -> 0.000000
5.63 -> 0.098175 -> ( 0.995185, 0.098017) -> 0.098175 -> 5.625000
11.25 -> 0.196350 -> ( 0.980785, 0.195090) -> 0.196350 -> 11.250000
16.88 -> 0.294524 -> ( 0.956940, 0.290285) -> 0.294524 -> 16.875000
22.50 -> 0.392699 -> ( 0.923880, 0.382683) -> 0.392699 -> 22.500000
28.13 -> 0.490874 -> ( 0.881921, 0.471397) -> 0.490874 -> 28.125000
33.75 -> 0.589049 -> ( 0.831470, 0.555570) -> 0.589049 -> 33.750000
39.38 -> 0.687223 -> ( 0.773010, 0.634393) -> 0.687223 -> 39.375000
45.00 -> 0.785398 -> ( 0.707107, 0.707107) -> 0.785398 -> 45.000000
50.63 -> 0.883573 -> ( 0.634393, 0.773010) -> 0.883573 -> 50.625000
56.25 -> 0.981748 -> ( 0.555570, 0.831470) -> 0.981748 -> 56.250000
61.88 -> 1.079922 -> ( 0.471397, 0.881921) -> 1.079922 -> 61.875000
67.50 -> 1.178097 -> ( 0.382683, 0.923880) -> 1.178097 -> 67.500000
73.13 -> 1.276272 -> ( 0.290285, 0.956940) -> 1.276272 -> 73.125000
78.75 -> 1.374447 -> ( 0.195090, 0.980785) -> 1.374447 -> 78.750000
84.38 -> 1.472622 -> ( 0.098017, 0.995185) -> 1.472622 -> 84.375000
90.00 -> 1.570796 -> ( 0.000000, 1.000000) -> 1.570796 -> 90.000000
95.63 -> 1.668971 -> (-0.098017, 0.995185) -> 1.668971 -> 95.625000
101.25 -> 1.767146 -> (-0.195090, 0.980785) -> 1.767146 -> 101.250000
106.88 -> 1.865321 -> (-0.290285, 0.956940) -> 1.865321 -> 106.875000
112.50 -> 1.963495 -> (-0.382683, 0.923880) -> 1.963495 -> 112.500000
118.13 -> 2.061670 -> (-0.471397, 0.881921) -> 2.061670 -> 118.125000
123.75 -> 2.159845 -> (-0.555570, 0.831470) -> 2.159845 -> 123.750000
129.38 -> 2.258020 -> (-0.634393, 0.773010) -> 2.258020 -> 129.375000
135.00 -> 2.356194 -> (-0.707107, 0.707107) -> 2.356194 -> 135.000000
140.63 -> 2.454369 -> (-0.773010, 0.634393) -> 2.454369 -> 140.625000
146.25 -> 2.552544 -> (-0.831470, 0.555570) -> 2.552544 -> 146.250000
151.88 -> 2.650719 -> (-0.881921, 0.471397) -> 2.650719 -> 151.875000
157.50 -> 2.748894 -> (-0.923880, 0.382683) -> 2.748894 -> 157.500000
163.13 -> 2.847068 -> (-0.956940, 0.290285) -> 2.847068 -> 163.125000
168.75 -> 2.945243 -> (-0.980785, 0.195090) -> 2.945243 -> 168.750000
174.38 -> 3.043418 -> (-0.995185, 0.098017) -> 3.043418 -> 174.375000
180.00 -> 3.141593 -> (-1.000000, 0.000000) -> 3.141593 -> 180.000000

22  NI-Lab.  2004/12/13(Mon) 22:19
>>21 の続き

185.63 -> 3.239767 -> (-0.995185, -0.098017) -> -3.043418 -> 185.625000
191.25 -> 3.337942 -> (-0.980785, -0.195090) -> -2.945243 -> 191.250000
196.88 -> 3.436117 -> (-0.956940, -0.290285) -> -2.847068 -> 196.875000
202.50 -> 3.534292 -> (-0.923880, -0.382683) -> -2.748894 -> 202.500000
208.13 -> 3.632467 -> (-0.881921, -0.471397) -> -2.650719 -> 208.125000
213.75 -> 3.730641 -> (-0.831470, -0.555570) -> -2.552544 -> 213.750000
219.38 -> 3.828816 -> (-0.773010, -0.634393) -> -2.454369 -> 219.375000
225.00 -> 3.926991 -> (-0.707107, -0.707107) -> -2.356194 -> 225.000000
230.63 -> 4.025166 -> (-0.634393, -0.773010) -> -2.258020 -> 230.625000
236.25 -> 4.123340 -> (-0.555570, -0.831470) -> -2.159845 -> 236.250000
241.88 -> 4.221515 -> (-0.471397, -0.881921) -> -2.061670 -> 241.875000
247.50 -> 4.319690 -> (-0.382683, -0.923880) -> -1.963495 -> 247.500000
253.13 -> 4.417865 -> (-0.290285, -0.956940) -> -1.865321 -> 253.125000
258.75 -> 4.516039 -> (-0.195090, -0.980785) -> -1.767146 -> 258.750000
264.38 -> 4.614214 -> (-0.098017, -0.995185) -> -1.668971 -> 264.375000
270.00 -> 4.712389 -> (-0.000000, -1.000000) -> -1.570796 -> 270.000000
275.63 -> 4.810564 -> ( 0.098017, -0.995185) -> -1.472622 -> 275.625000
281.25 -> 4.908739 -> ( 0.195090, -0.980785) -> -1.374447 -> 281.250000
286.88 -> 5.006913 -> ( 0.290285, -0.956940) -> -1.276272 -> 286.875000
292.50 -> 5.105088 -> ( 0.382683, -0.923880) -> -1.178097 -> 292.500000
298.13 -> 5.203263 -> ( 0.471397, -0.881921) -> -1.079922 -> 298.125000
303.75 -> 5.301438 -> ( 0.555570, -0.831470) -> -0.981748 -> 303.750000
309.38 -> 5.399612 -> ( 0.634393, -0.773010) -> -0.883573 -> 309.375000
315.00 -> 5.497787 -> ( 0.707107, -0.707107) -> -0.785398 -> 315.000000
320.63 -> 5.595962 -> ( 0.773010, -0.634393) -> -0.687223 -> 320.625000
326.25 -> 5.694137 -> ( 0.831470, -0.555570) -> -0.589049 -> 326.250000
331.88 -> 5.792311 -> ( 0.881921, -0.471397) -> -0.490874 -> 331.875000
337.50 -> 5.890486 -> ( 0.923880, -0.382683) -> -0.392699 -> 337.500000
343.13 -> 5.988661 -> ( 0.956940, -0.290285) -> -0.294524 -> 343.125000
348.75 -> 6.086836 -> ( 0.980785, -0.195090) -> -0.196350 -> 348.750000
354.38 -> 6.185011 -> ( 0.995185, -0.098017) -> -0.098175 -> 354.375000
360.00 -> 6.283185 -> ( 1.000000, -0.000000) -> -0.000000 -> 360.000000

23  NI-Lab.  2004/12/27(Mon) 19:56
// 動作未確認
// コンパイルすらしていない
// URLデコードする関数
void url_decode(char * dest, const char * src){

if(!src || !dest){
return;
}

const char * pSrc = src;
char * pDest = dest;

for(; *pSrc != '\0'; ++pDest, ++pSrc){
if(*pSrc == '+'){ // + to space
*pDest = ' ';
continue;
}else if( *pSrc == '%' ){ // % to double bytes char
char tmp[3];
tmp[0] = *(++pSrc);
tmp[1] = *(++pSrc);
tmp[2] = '\0';
int num = strtol( tmp, NULL, 16 );
*pDest = num;
continue;
}
*pDest = *pSrc;
}
}