🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌🌌
I study C everyday step by step with patience, passion!
#include <stdio.h>
int main(void)
{
printf("hello, world");
}
<여기서 배운 것>
- C언어에 시작할 때 Library #include stdio.h
- 라이브러리와 메인 코드 시작 전에 한 줄
- 프로그램이 실행되기 위해서는 main이 필요하다
- 프로그램 컴파일: Makefile
- 어떻게 디렉토리 분류, 커밋 메시지 남기는 지
- 커밋은 하나씩만! (한 커밋에는 하나의 내용만) https://github.com/notypicalus/c_programming/commit/1626848c392cafec0cc341908f85d3cab6b5f589
- Syntax 익숙해지기: Linux Kernel Coding Style https://www.kernel.org/doc/html/v4.10/process/coding-style.html?fbclid=IwAR2ob1ConygIGPMiyl-JcXsEf4DLp1lfmYpJh-9tBmH8cF64qBDNqnzpGko
- Main point: int, float,
- 계산한 값을 어떻게 프린트할 수 있는지: %d, %f
int main()
{
printf("A program prints Fahrenheit-Celsius\n");
int lower, upper, step;
int celsius, fahr;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf("화씨\t 섭씨\n");
while(fahr <= upper)
{
celsius = 5 * (fahr - 32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}
int main()
{
//Variable declaration
float fahr, celsius;
float lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
printf("화씨\t섭씨\n");
while(fahr <= upper)
{
celsius = (5.0 / 9.0) * (fahr-32.0);
printf("%3.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
ex1_5 Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0
<여기서 배운 것>
- getchar & putchar function 차이점
- buffer
"The simplest example is a program that copies its input to its output one character at a time"
read a character while (character is not end-of-file indicator) output the character just read read a character
1st version:
int main()
{
int c;
c = getchar();
while (c != EOF)
{
putchar(c);
c = getchar();
}
}
2nd version:
int main()
{
int c;
while ((c = getchar()) != EOF)
putchar(c);
}
<여기서 배운 것>
- datatype char & int: 왜char를 사용하지 않고 int를 사용 했는 지
- EOF (end of file)
1st version:
int main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
2nd version:
int main()
{
double nc;
for (nc = 0; getchar() != EOF; ++nc)
;
printf("%.0f\n", nc);
}
ex1_9 Write a program to copy its input to output, replacing each string of one ore more blanks by a single blank.
ex1_10 Write a program to copy its input to its output, replacing each tab by /t, each backspace by /b, and each backslash by \. This makes tabs and backspaces visible in an unambiguous way.
✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨