LoginSignup
0

More than 3 years have passed since last update.

C言語の現場で使うイロイロなまとめ

Last updated at Posted at 2020-04-02

C言語

型の一覧
void  戻り値なし

void test(void){
   //テストコード 
   printf("\n");
   return;
}

char  文字型

#include <stdio.h>

// 関数プロトタイプ宣言
void test(char);

int main(void){
test('a');

}

void test(char moji){
   //テストコード 
   printf("%c\n",moji);
   return;
}

int   整数型

#include <stdio.h>

// 関数プロトタイプ宣言
void test(int);

int main(void){
test(10);     
}

void test(int num){
   //テストコード 
   printf("%d\n",num);
   return;
}

float  小数点

#include <stdio.h>

// 関数プロトタイプ宣言
void test(float);

int main(void){
test(10.1);     
}

void test(float fl){
   //テストコード 
   printf("%f\n",fl);
   return;
}

double 小数点(大きい)

#include <stdio.h>

// 関数プロトタイプ宣言
void test(double);

int main(void){
test(10.1234567);     
}

void test(double db){
   //テストコード 
   printf("%lf\n",db);
   return;
}

struct 構造体
┗後でかく
union 共用体
┗後でかく
enum 列挙型
┗後でかく

ランダム
6を法とする合同(さいころ)

rand() % 6 + 1;


int roll_dice(void) {
    int roll_dice;
    srand((unsigned)time(NULL));
    roll_dice = rand() % 6 + 1;
    return roll_dice;

小技 エンターで次の処理に移る方法

  //エンターキーを押すと次の処理へ移る

        void enter(void) {
            char dummy;
            printf("エンターキーを押してください\n");
            scanf("%c", &dummy);
        }

呼び出す場合

enter();

と処理の途中で入力



#include<stdio.h>
#include<stdlib.h>
#include<time.h>
// プロトタイプ宣言

int roll_dice(void);
void enter(void);

int main(void)
{
    int cp, cp1;
    int my, my1;


    //コンピュータ
    cp = roll_dice();
    printf("%d\n", cp);
        cp1 = roll_dice();
    printf("%d\n", cp1);

        printf("あなたの番です\n");


    //自分2回さいころを振る
    enter();
    my = roll_dice();
    printf("さいころの数は%d:\n", roll_dice());
    enter();
    my1 = roll_dice();
    printf("さいころの数は%d:\n", roll_dice());

}


    //6を法とする合同
    //さいころの数をランダムで出す
    int roll_dice(void){

        int roll_dice;
        srand((unsigned)time(NULL));
        roll_dice = rand() % 6 + 1;
        return roll_dice;
    }

        //エンターキーを押すと次の処理へ移る

        void enter(void) {
            char dummy;
            printf("エンターキーを押してください\n");
            scanf("%c", &dummy);
        }

Linux系

・コマンド

移動

cd       ・・・ ホームディレクトリに移動
cd ..      ・・・ 1つ上のディレクトリに移動
cd ファイル名 ・・・ 指定したのファイル名のディレクトリに移動

ディレクトリ表示

ls    ・・・ ディレクトリのファイル/フォルダを一覧表示
ls -1  ・・・ ディレクトリのファイル/フォルダを縦に一覧表示
ls -l ・・・ ディレクトリのファイル/フォルダの詳細を一覧表示

画面クリア

clear

vim

vim 編集するファイル名


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