●コンパイル時のオプション(-Wall)
gcc -o hello hello.c -Wall
●__FILE__
ファイル名を出力できる
●__LINE__
行番号を出力できる
●エラーメッセージ、エラー番号
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
int
main()
{
int sock;
sock = socket(3000, 4000, 5000);
if (sock < 0) {
printf("file:%s\n", __FILE__);
printf("line:%d\n", __LINE__);
perror("socket");
printf("%d\n", errno);
return 1;
}
return 0;
}
実行結果
file:err.c
line:15
socket: Invalid argument
22
●getchar関数
文字を1文字受け取る