Skip to content

Instantly share code, notes, and snippets.

@sorah
Created July 1, 2009 11:53
Show Gist options
  • Save sorah/138740 to your computer and use it in GitHub Desktop.
Save sorah/138740 to your computer and use it in GitHub Desktop.
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>
int _tes(va_list ap, char c)
{
if(c == '\0')//もしもcが\0なら
return 1;//1を返して終了
write(1, &c, 1);//標準出力へ!!!!
//printf("%d\n",c);
return _tes(ap, va_arg(ap, int));//同じリストと、次の引数を再帰的に渡す
}
int tes(char c, ...)
{
va_list ap;//可変引数リストの定義?
va_start(ap, c);//上の仕様準備
_tes(ap, c);//_tesを呼び出す cはこの時、1番はじめの引数(この場合は'd')となる
va_end(ap);//可変引数リストの使用終了
}
int main(void)
{
tes('d','a','i','k','i','4','1','t','i','\n','\0');//可変長引数のテスト用関数の呼び出し
return 0;//終了
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment