LoginSignup
0
0

More than 1 year has passed since last update.

C言語頻出関数まとめ

Last updated at Posted at 2021-06-27

本ページの見方

ライブラリ名(○○.h)

関数名

  • ポイントや作業内容、豆知識
コード・説明

C言語頻出関数

stdio

printf()

  • 文字を出力する関数。
  • 第二引数に変数を指定することで変数の値を表示することが可能。
printf(const char *format, ... );

printf("Hello World!");
 -> Hello World!

int a = 10;
printf("%d日", a);
 -> 10

fopen()

  • ファイルを読み込む関数。
  • この関数を利用することでCSVファイルなどから値を読み取ることが可能。
  • この関数を利用した後はfclose関数を利用してファイルを閉じる必要がある。
fopen(const char *filename, const char *mode);
 //modeはr(読み取り), w(書き込み)のいずれかを使う場合が多い。

FILE *file = fopen("ファイルの名前", "r");

fclose(file);

string

strcmp()

  • 文字列を比較する関数。
  • ==では比較することのできない文字列を比較してくれる。
strcmp(const char *s1, const char *s2);

char *a = "Qiita";
strcmp("Qiita", a);
 -> Trueを返す

strcpy()

  • 文字列をコピーする関数。
char *strcpy(char *s1, const char *s2);
 //s1にs2の文字列をコピーする

char *a;
strcpy(a, "Qiita");
printf("%s", a);
 ->Qiitaと出力される

math

round()

  • 値を四捨五入する関数。
  • 切り上げはroundup()関数,切り捨てはrounddown()関数を用いる。
round(double x);
 //xの値を四捨五入する

int a = round(3.6);
 ->aに4が格納される

より詳しく知りたい方は以下のリンクから(全て英語です)
C言語ドキュメント

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0