char b[100];
b = "abc";
int compare(char *s1, char *s2)
{
if (s1 == s2) {
printf("一致しました\n");
return 0;
} else {
printf("差がありました\n");
return 1;
}
}
char str1[] = "string";
char *str2 = "string";
printf("%s\n", str1);
printf("%s\n", str2);
void foo(void)
{
char str1[] = "string";
...
}
char *s1 = "Hello, ";
char *s2 = "world!";
strcat(s1, s2);
char *yes_or_no(int yn)
{
char tmp[16];
if (yn == 0) {
strcpy(tmp, "No");
} else {
strcpy(tmp, "Yes");
}
return tmp;
}
char str[6] = "string";
printf("%s\n", str);
char *p = "Hello, world!";
p[0] = tolower(p[0]);
char *strcpy(char *dst, char *src)
{
char *tmp;
tmp = dst;
while ((*src++ = *dst++ ) != NULL)
;
return tmp;
}
printf("%s\n", NULL);
((int *)p)++
char *alloc_string(char *string)
{
char *p;
size_t len;
len = strlen(string);
p = malloc(len);
strcpy(p, string);
return p;
}
int i, j;
long l;
i = 100;
j = 500;
l = i * j;
printf("%ld\n", l);
float x;
for (x = 0.0; x < 1.0; x += 0.1) {
/* 必要な処理 */
}
#define TRUE (1 == 1) #define FALSE (!TRUE)
printf("hello world!\n"); // お決まりの文句
/* i = 1; /* i = foo(i); */
static int
foo(void)
{
...
}
#define begin {
#define end }
a = 1, b = 2, c = 3;
int a[10];
int i = 0;
while (i < 10)
a[i] = i++;
int i = 7;
printf("%d\n", i++ * i++);
int a[10];
int i = 0;
while (i < 10)
a[i] = i++;
int i = 3;
i = i++;
kcode = getchar() << 8 + getchar();
kcode = getchar() + getchar() << 8;
i = foo() & bar(); /* (1) */
i = foo() && bar(); /* (2) */
i = (c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc) /* (1) */
i = c >= 0x81 && (c <= 0x9f || (c >= 0xe0 && c <= 0xfc)) /* (2) */
#if (sizeof(int) == 2)
...
#else
...
#endif
#define swap(a, b) (a ^= b, b ^= a, a ^= b)
#define swap(a, b) (a ^= b ^= a ^= b)
#define Paste(a, b) a/**/b
if (isspace(c = *s++) == 0)
putchar(c);
#include <stdio.h>
int main(void)
{
char s[14] = "hello, world!";
printf("%s\n", s);
return 0;
}
mallocやfreeを呼び出すと暴走する。
if ((*p++ == 'A') && (*p == 'Z')) 文
という書き方は正しいか?
gotoを取り除くにはどうすればよいか?
handleの部分に実際は長い文字列を格納するような使い方は正しいか。
struct nameholder {
int id;
char handle[1];
};
struct nameholder {
struct nameholder *next;
char name[256];
};
np = malloc(sizeof(nameholder) - (255 - strlen(s)));
struct foo {
char c1;
char c2;
};
typedef struct {
LIST *next;
char *body;
} LIST;
struct list1 {
struct list2 *p2;
int i;
};
struct list2 {
struct list1 *p1;
char *s;
};
if ((c1 = getchar()) & (c2 = getchar()) & 0x80) {
/* EUC漢字コードの処理 */
}
printf("a = %d\n", a);
a << 3;
printf("a = %d\n", a);
/* A */
c = getc(fp);
c += getc(fp) * 256;
/* B */
c = getc(fp);
c += getc(fp) << 8;
!」と「~」はどこが違うのか?
if (((c1 = getchar()) >= 0x80) && ((c2 = getchar()) >= 0x80)) {
/* EUC漢字コードの処理 */
}
void str_check(char *s1, char *s2)
{
if (s1 == s2) {
printf("文字列が一致しました\n");
}
islowerを呼んでいるのか?
if (islower(c))
c = toupper(c);
>
str_arrayは文字列へのポインタが100個格納された配列である。
次のコードはなぜうまく動作しないのか。
char *str[];
qsort(str_array, 100, sizeof(char *), strcmp);
qsortを呼び出している行で、型に関する警告が出る。
indexという関数は何をするのか?
a = ((a + 99) / 100) * 100;
struct area window = {0, 0, 1023, 767,};
struct array {
int item[10];
};
/* 与えられたintの中の1であるビットの数を返す。
* 最上位2ビットは利用できない
*/
int numofbits(int bits)
{
int num;
num = (bits >> 1) & 03333333333;
num = bits - num - ((num >> 1) & 03333333333);
num = ((num + (num >> 3)) & 0707070707) % 077;
return num;
}
int numofbits(long bits)
{
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
#define is_kanji1st(c) ((unsigned int) (c ^ 0x20) - 0xa1 < 0x3c)
len = strlen(s);
buf = malloc(len);
strcpy(buf, s);
/* 1 */
len = strlen(s);
buf = malloc(len + 1);
/* 2 */
len = strlen(s) + 1;
buf = malloc(len);
int *array; array = (int *) malloc(sizeof(int) * 16);
'a'の型は何か?
int main(argc, argv)
int argc;
char *argv[];
{
....
char const *s; と、char *const s; の違いは?
memcpy関数とmemmove関数の違いは?
fgetpos関数とftell関数の違いは?
Warning test.c 22: Call to function 'printf' with no prototype in function main
mallocで確保するにはどのようにすればよいか?
mallocで確保するには
どうすればよいか?
NULLであるかどうかのテストを、
if (p != NULL)ではなくif (p)と書くのは正しいか?
static long random_x = 1L;
static const long P = 0x7FFFFFFFL;
(略)
random_x += P + 1;