Iloilo summary used in the field of C language

C language

** List of types ** void No return value

void test(void){
   //Test code
   printf("\n");
   return;
}

char character type

#include <stdio.h>

//Function prototype declaration
void test(char);

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

void test(char moji){
   //Test code
   printf("%c\n",moji);
   return;
}

int integer type

#include <stdio.h>

//Function prototype declaration
void test(int);

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

void test(int num){
   //Test code
   printf("%d\n",num);
   return;
}

float decimal point

#include <stdio.h>

//Function prototype declaration
void test(float);

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

void test(float fl){
   //Test code
   printf("%f\n",fl);
   return;
}

double decimal point (large)

#include <stdio.h>

//Function prototype declaration
void test(double);

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

void test(double db){
   //Test code
   printf("%lf\n",db);
   return;
}

struct structure ┗ Write later union union ┗ Write later enum enum ┗ Write later

random Joint (dice) with 6 as the law

rand() % 6 + 1;

Example


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

How to move to the next process with the trick enter

  //Press the enter key to move to the next process

        void enter(void) {
            char dummy;
            printf("Press enter\n");
            scanf("%c", &dummy);
        }

When calling

enter();

And input in the middle of processing

Example



#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//prototype declaration

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

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


    //Computer
    cp = roll_dice();
    printf("%d\n", cp);
        cp1 = roll_dice();
    printf("%d\n", cp1);

        printf("It's your turn\n");
  

    //Shake yourself twice
    enter();
    my = roll_dice();
    printf("The number of dice%d:\n", roll_dice());
    enter();
    my1 = roll_dice();
    printf("The number of dice%d:\n", roll_dice());

}


    //Joint with 6 as the law
    //Randomly output the number of dice
    int roll_dice(void){

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

        //Press the enter key to move to the next process

        void enter(void) {
            char dummy;
            printf("Press enter\n");
            scanf("%c", &dummy);
        }

Linux series

·command

Move

cd ・ ・ ・ Move to home directory
cd ..・ ・ ・ Move to the next higher directory
cd file name ・ ・ ・ Move to the directory with the specified file name

Directory display

ls ・ ・ ・ Directory files/List folders
ls -1 ・ ・ ・ Directory files/List folders vertically
ls -l ・ ・ ・ Directory files/List folder details

Clear screen

clear

vim

vim file name to edit


Recommended Posts