「C言語」strlen関数で文字列の長さを取得するサンプル
構文
strlen(str)
文字列strの長さを取得します。
サンプルコード
#include <stdio.h>#include <string.h>int main(vo ...「C言語」strcat関数で文字列を連結するサンプル
構文
char *strcat(char * restrict s1,const char * restrict s2
);
文字列を連結します。
使用例
「C言語」strcpy関数で文字列をコピーするサンプル
構文
char *strcpy(char *s1, const char *s2);
文字列のコピー
s1 コピー先
s2 コピー元
使用例
「C言語」strcpy関数でポインタ文字列を文字型配列にコピーする
説明
char *strcpy(char * restrict s1,const char * restrict s2
);
使用例
「C言語」break文のサンプル
構文
do {
if(条件式){
//some code
}
}while(条件式)
サンプルコード
#include <stdio.h>int main(void ...「C言語」continueでdo..whileループをスキップする方法
構文
do{//ループをスキップ if (条件式){//some code continue; }} while(条件式);サンプルコード
#include <stdio.h>int main(void) ...「C言語」do~while文で同じ処理を繰り返すサンプル
構文
do{
some code
}while(条件式);
サンプルコード
#include <stdio.h>int main(void){/* 変数の宣言 */int m = ...「C言語」後置演算子を使うサンプル
構文
変数名–
変数名++
サンプルコード
「C言語」前置演算子を使うサンプル
構文
–変数名
++変数名
使用例
#include <stdio.h>int main(void){ int m = 19; int n = 19; int res1; in ...「C言語」char型変数を使うサンプル
char変数の定義
char 変数名
サンプルコード
#include <stdio.h> int main(void){ char cftA, cftB; cftA = 'T'; cftB = ...「C言語」while文のサンプル
構文
while(条件式){some code}
サンプルコード
#include <stdio.h>int main(){ int i; i=5; while(i < 10){ print ...「C言語」関数のプロトタイプ宣言を使うサンプル
構文
戻り値の型 関数名(引数の型);
サンプルコード
「C言語」引数、戻り値ありの関数を呼び出すサンプル
構文
戻り型 関数名(型 引数1,型 引数2)
サンプルコード
「C言語」グローバル(global)変数とローカル(local)変数を使うサンプル
使用例
#include <stdio.h>/* グローバル変数 */int cftA=120; void func(){/* 関数のローカル変数 */int cftB=140; printf("function p ...「C言語」引数ありの関数を呼び出すサンプル
構文
void 関数名(型 引数1,型 引数2);
サンプルコード
#include <stdio.h>void testfunc(int x, int y){/* 変数の宣言 */int res ...「C言語」引数、戻り値なしの関数を呼び出すサンプル
構文
main() {
void 関数名();
}
サンプルコード
#include <stdio.h> void testfunc(void){ printf("this is ...「C言語」for文で繰り返し処理をするサンプル
構文
for (初期化;条件式;変化式){some code}
サンプルコード
「C言語」switch文のサンプル
構文
switch(条件式){ case 数値1://some code break; case 数値2://some code break; default://some code break;}サンプルコード
# ...