πππππππππππππππππ
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.
β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨β¨