강좌 : 부스트캠프 모두를 위한 컴퓨터과학(cs50 2019)
#include <stdio.h>
int main(void)
{
}
ptintf();
→ printf("hello,world");
\n
→ printf("hello,world\n");
쌍따옴표 안에 작성
#include <stdio.h>
int main(void)
{
printf("hello.world\n");
}
clang 파일이름.c
→ $ clang hello.c
결과 : a.out 머신코드 생성
$ ./a.out
-o 저장할이름
→ $ clang -o hello hello.c
결과 : hello 이름의 머신코드 생성
$ ls
머신코드 뒤에는 * 가 붙어 머신코드와 소스코드를 구분
$ rm
get_string("");
string 변수이름 = get_string();
string answer = get_string("What's your name?\n");
%s, 변수
→ printf("hello, %s\n", answer);
문자열을 받기때문에 string에서의 s를 뒤에붙임
#include <cs50.h>
수업을 위해서 cs50라이브러리를 만든것
원래는 C표준 라이브러리사용
-l라이브러리
→ $ clang -o string string.c -lcs50
make 파일이름
→ $ make string, make hello
컴파일해서 바로 프로그램 생성 -o, -l 와 동일한 과정 실행
📖 연습해보기
#include <stdio.h>
#include <cs50.h>
int main(void)
{
string animal = get_string("좋아하는 동물을 알려주세요\n");
printf("내가 좋아하는 동물은 %s\n", animal);
}
$make string
./string
int count = 0;
count = count + 1;
= count += 1;
= count++;
if (조건)
{
printf("");
}
if (조건)
{
printf("");
}
else
{
printf("");
}
if (조건)
{
printf("");
}
else if (조건2)
{
printf("");
}
else
{
printf("");
}
// 무한정 출력
while(true)
{
printf("");
}
// 특정 횟수만큼 출력
int i = 0;
while (i < 50)
{
printf("");
i += 1;
}
for(변수초기화; 변수조건; 변수증가)
{
printf("");
}
→ for (int i =0; i < 50;, i += 1)
{
printf("");
}
📖 연습해보기
#include <stdio.h>
int main(void)
{
for (int i = 0; i<10; i++)
{
printf("개발공부는 재미있다\n");
}
}
$ make for
$ ./for