2012年1月23日月曜日

Hoge.c

/*
============================================================================
Name : Hoge.c
Author : M♂DS
Version :
Copyright : M♂DS
Description : Hoge in C, Ansi-style
============================================================================
*/

#include
#include

#define BUFFLEN 256

struct _list {
struct _list *prev;
struct _list *next;
char buff[BUFFLEN];
};

typedef struct _list LIST;

LIST * makeList(LIST *current) {
if (current == (LIST *) NULL) {
current = (LIST *) calloc(1, sizeof(LIST));
current->prev = (LIST *) NULL;
} else {
current->next = (LIST *) calloc(1, sizeof(LIST));
current->next->prev = current;
current = current->next;
}
current->next = (LIST *) NULL;
return current;
}

int main(void) {
LIST *q, *p;
int i;

p = q = (LIST *) NULL;
for (i = 0; i < 100; i++) {
p = makeList(p);
if (q == NULL) {
q = p;
}
snprintf(p->buff, BUFFLEN, "hoge %03d", i);
}

for (p = q; p; p = p->next) {
puts(p->buff);
}
return EXIT_SUCCESS;
}

次の案件に備えて11年ぶりくらいに
C言語を使ってみたが
意外と忘れてなくて良かったε-(´∀`*)ホッ

0 件のコメント: