arch-spatula / arch-spatula.github.io

Arch-Spatula의 레시피
https://arch-spatula.github.io/
3 stars 0 forks source link

[Draft] C 언어 CLI #289

Closed arch-spatula closed 2 months ago

arch-spatula commented 4 months ago

글쓰기 주제

draft/diy-cs-c-cli

참고할 자료

arch-spatula commented 3 months ago

버퍼에 문자열이 들어가면 버퍼를 비워줘야 하는 이유는 무엇인가?

https://www.tcpschool.com/c/c_string_io

arch-spatula commented 3 months ago
int main(int argc char *argv )

위는 무엇을 의미하는가?

arch-spatula commented 3 months ago

C 언어로 난수를 생성하는 방법은 무엇인가?

#include <stdio.h>
#include <stdlib.h> //srand, rand를 사용하기 위한 헤더파일
#include <time.h> // time을 사용하기 위한 헤더파일
 
int main() {
  srand(time(NULL)); // 난수 초기화
  for (int i = 0; i< 10; i++) {
    int random = rand() % 5; // 0 ~ 4 사이의 숫자를 뽑아서 random 변수에 저장
    printf("%d ", random); // 출력
  }
  return 0;
}

https://ludeno-studying.tistory.com/39

https://stackoverflow.com/questions/822323/how-to-generate-a-random-int-in-c

arch-spatula commented 3 months ago
scanf("%d %d %d", &num1, &num2, &num3);

표준 입출력에 숫자를 받는 방법

arch-spatula commented 3 months ago

함수의 선언과 구현은 다릅니다. C 언어는 시그니쳐를 선언해야 구현하고 호출이 가능합니다. 이것은 컴파일러가 요구합니다.

https://zapiro.tistory.com/entry/C%EC%96%B8%EC%96%B4-%ED%95%A8%EC%88%98function%EC%9D%98-%EA%B8%B0%EC%B4%88

arch-spatula commented 3 months ago

scanf 검증 방법은 무엇인가?

https://stackoverflow.com/questions/2023079/check-if-a-value-from-scanf-is-a-number

arch-spatula commented 3 months ago

fgets란 무엇인가?

#define MAX_INPUT_LENGTH 100

int main() {
        // 생략...
        /* 표준입력을 문자열로 받음 */
        char input[MAX_INPUT_LENGTH];
        if (fgets(input, sizeof(input), stdin) == NULL) {
            printf("입력 오류\n");
            return 1;
        }
}
arch-spatula commented 3 months ago

C 언어로 작성한 코드를 컴파일해서 얻은 실행파일을 gitignore하는 방법은 무엇인가?

# Ignore compiled executables
*.exe
*.out
*.o

.gitignore 파일에 위를 작성합니다.

arch-spatula commented 3 months ago

image

arch-spatula commented 3 months ago

image

arch-spatula commented 3 months ago

image

arch-spatula commented 3 months ago

image

arch-spatula commented 3 months ago

image