C

文字列を区切り文字で分解

#include <stdio.h> #include <string.h> int main() { char s[] = "This is a sentence."; char *p; for (p = strtok(s, " \t\n"); p; p = strtok(NULL, " \t\n")) printf("%s\n", p); return 0; } C言語では定番の方法。</string.h></stdio.h>

日付から曜日を求めるC言語プログラム

/* 0 = Sunday, 1 <= m <= 12, y > 1752 or so */ int day_of_week(int y, int m, int d) { static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; y -= m < 3; return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; } C FAQに載っている、日付から曜日…