[C] λ©±μΉ κ΅¬νκΈ° (while λ¬Έ)
#include <stdio.h>
int main(void)
{
int n;
int x;
int i = 1;
printf("μ«μλ₯Ό μ
λ ₯νμΈμ ");
scanf_s("%d", &x);
printf("====================\n");
printf("n nμμ κ³±\n");
printf("====================\n");
n = 1;
while (n <= x)
{
printf("%d %d\n",n,n*n);
n++;
}
return 0;
}
[C] νμ ꡬνκΈ° + μμλμ¬λκΉμ§μ λ ₯λ°κΈ°
#include <stdio.h>
#include<limits.h>
int main()
{
int jumsu = 0;
float total, average;
int i = 0;
total = 0;
printf("μ’
λ£νλ €λ©΄ μμλ₯Ό μ
λ ₯νμμ€ \n");
//μ μλ€μ μμκ° λμ¬ λ κΉμ§ λ°λ³΅ν΄μ μ
λ ₯λ°μμ μ΄μ μ ꡬνκ³
//μ
λ ₯ν κ°μλ₯Ό μΌλ€
while ( jumsu >= 0 )
{
printf("μ μλ₯Ό μ
λ ₯νμμ€ \n");
scanf_s("%d", &jumsu);
total += jumsu;
i++;
}
total = total - jumsu;
i--;
average = total / i;
printf("μ΄μ = %.2f\n", total);
printf("νκ· = %.2f\n", average);
return 0;
}
[C] μ΅λκ°κ΅¬νκΈ° +EOF
#include <stdio.h>
#include<limits.h>
int main()
{
int num;
int min = INT_MAX; //μΈνΈμ΅λκ°
int max = INT_MIN;
printf("νΉμ μ μλ₯Ό μ
λ ₯νμΈμ.\n μ’
λ£λ Ctrl+z \n");
while (scanf_s("%d", &num) != EOF) { //-1
if (num > max)
max = num;
}
printf("μ΅λ = %d\n", max);
return 0;
}
//eof ctrl + z 3λ² λλ¬μΌ μ’
λ£
[C] νμ ꡬνκΈ° + μμλμ¬λκΉμ§μ λ ₯λ°κΈ°
#include <stdio.h>
#include<limits.h>
int main()
{
int jumsu = 0;
float total, average;
int i = 0;
total = 0;
printf("μ’
λ£νλ €λ©΄ μμλ₯Ό μ
λ ₯νμμ€ \n");
//μ μλ€μ μμκ° λμ¬ λ κΉμ§ λ°λ³΅ν΄μ μ
λ ₯λ°μμ μ΄μ μ ꡬνκ³
//μ
λ ₯ν κ°μλ₯Ό μΌλ€
while ( jumsu >= 0 )
{
printf("μ μλ₯Ό μ
λ ₯νμμ€ \n");
scanf_s("%d", &jumsu);
total += jumsu;
i++;
}
total = total - jumsu;
i--;
average = total / i;
printf("μ΄μ = %.2f\n", total);
printf("νκ· = %.2f\n", average);
return 0;
}
[C] μ«μ ν© κ΅¬νκΈ° +EOF
#include <stdio.h>
#include<limits.h>
int main()
{
int sum=0;
int num;
int i = 0;
printf("μ«μλ₯Ό μ
λ ₯νμΈμ.");
while (scanf_s("%d", &num) != EOF){
sum += num;
}
printf("%d",sum);
return 0;
}
[C] λ©±μΉ κ΅¬νλ ν¨μ λ§λ€κΈ°
#include <stdio.h>
int square(int x);
int main()
{
int n;
printf("μ«μ nμ μ
λ ₯νμΈμ. ");
scanf_s("%d", &n);
printf("squareν¨μ κ²°κ³Ό = %d", square(n));
return 0;
}
int square(int x) {
return (x*x);
}
[C] λ©±μΉ κ΅¬νλ ν¨μ λ§λ€κΈ° + 리ν΄κ°μμ΄
void power(int x); //ν¨μ μ μΈ //νμ맀κ°λ³μ
int main() {
power(3);
return 0;
}
void power(int x) { //νμ맀κ°λ³μ
printf("power ν¨μ νΈμΆ κ²°κ³Ό : %d",x*x);
}
[C] xμ yμΉ κ΅¬νλ ν¨μ λ§λ€κΈ°
#include <stdio.h>
#include <math.h>
int power(int x, int y); //ν¨μ μ μΈ //νμ맀κ°λ³μ
int main() {
int x, y;
printf("λκ°μ μ μ μ
λ ₯\n");
scanf_s("%d%d",&x,&y);
int result = power(x,y);
printf("%dμ %dμΉ = %d", x, y, result);
return 0;
}
int power(int x, int y) { //νμ맀κ°λ³μ
int result = 1;
for (int i = 1; i <= y; i++)
result *= x;
return result;
}
[C] ν° μλ₯Ό ꡬνλ ν¨μ λ§λ€κΈ°
//ν¨μ -> λ°°μ΄
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
//ν° μλ₯Ό ꡬνλ ν¨μ
int max(int x, int y);
int main() {
int x, y;
printf("λκ°μ μ μ μ
λ ₯\n");
scanf_s("%d%d",&x,&y);
int result = max(x,y);
printf("%dμ %d μ€ ν°μ = %d", x, y, result);
return 0;
}
int max(int x, int y) {
int result;
if (x > y){
result = x;
}
if (x < y) {
result = y;
}
return result;
}
[C] μμ ꡬνλ ν¨μ λ§λ€κΈ°
//ν¨μ -> λ°°μ΄
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//μμλ₯Ό ꡬνλ ν¨μ
int prime(int x);
int main() {
int x;
printf("μ μ x μ
λ ₯ \n");
scanf_s("%d",&x);
if (prime(x) == 1)
printf("%dλ μμo.",x);
else
printf("%dλ μμx.",x);
return 0;
}
int prime(int x) {
//μ½μ 2κ°λ§
int count = 0;
for (int i = 1; i <= x; i++) {
if (x % i == 0) {
count++;
}
}
return (count == 2); // 0 1 λ°ν 0μ κ±°μ§
}
0 λλλ λλ¨Έμ§ 0
[C] μ λλ , λμ΄ κ΅¬νκΈ°
------
//ν¨μ -> λ°°μ΄
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define PI 3.14
//μ λλ ꡬνλ ν¨μ
double circum(int x);
int main() {
int x;
printf("μ μ xλ₯Ό μ
λ ₯ \n");
scanf_s("%d", &x);
printf("μμ λλ λ %.2lf ", circum(x));
return 0;
}
double circum(int x) {
return (2 * PI * x);
}
[C/λ°°μ΄] νμ ꡬνκΈ°
//ν¨μ -> λ°°μ΄
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define PI 3.14
int main() {
int jumsu[3] = {0, };
float total = 0, avg = 0;
for (int i = 0; i < 3; i++)
{
scanf_s("%d",&jumsu[i]);
total += jumsu[i];
}
avg = (float) (total / 3); //totalμ΄ μ€μνμ΄λκΉ μλ νλ³ν
printf("κ΅μ΄ :%d\n", jumsu[0]);
printf("μμ΄ : %d\n", jumsu[1]);
printf("μν : %d\n", jumsu[2]);
printf("μ΄μ : %.2lf\n", total);
printf("νκ· : %.2lf", avg);
return 0;
}
[C/λ°°μ΄] λ°°μ΄ μΆλ ₯νκΈ°
//ν¨μ -> λ°°μ΄
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 5
int main() {
int a[SIZE];
for (int i = 0; i < SIZE; i++)
{
scanf_s("%d", &a[i]);
printf("%d ", a[i]);
}
printf("\n");
for (int i = SIZE-1 ; i >= 0; i--)
{
printf("%d ", a[i]);
}
return 0;
}
[C/λ°°μ΄] λ³ μ°κΈ°
//ν¨μ -> λ°°μ΄
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 5
int main() {
int a[SIZE] = { 10,20,30,40,50 };
for (int i = 0; i < SIZE; i++)
{
printf("λ²νΈ %d ", a[i]);
for (int s = 0; s < a[i]; s++) {
printf("*");
}
printf("\n");
}
return 0;
}
[C/λ°°μ΄] μ£Όμ¬μ
//μ£Όμ¬μ
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 6
#include <stdlib.h>
int main() {
int freq[SIZE] = { 0 };
for (int i = 0; i < 10000; i++)
{
++freq[rand() % 6];
}
printf("===================\n");
printf("λ©΄ λΉλ\n");
printf("===================\n");
for (int i = 0; i < SIZE; i++)
printf("%3d %3d\n", i, freq[i]);
return 0;
}
λΉλμ κ³μ°νλ μκ³ λ¦¬μ¦
λλ€μλ₯Ό % 6μΌλ‘ λλ λλ¨Έμ§λ€μ μΈλ±μ€λ‘ μ‘κ³
0-5κΉμ§ μΈλ±μ€
λλ¨Έμ§ κ°μ΄ 0-5μ¬μ΄μ κ°μ΄ λμ€λλ°
λμ¬λλ§λ€ μΈλ±μ€ κ°μ ++1 ν΄μ€λ€
λΉλμκ° μ¦κ°νλ€
[C] νμ¨κ³μ°
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
int won = 0;
int dol = 0;
printf("μμ μ
λ ₯νμΈμ");
scanf("%d", &won);
dol = won/1200;
printf("μ %d \n λ¬λ¬ %d", won, dol);
return 0;
}
[C/1νκΈ°]
//if λ¬Έ
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void) {
//κ΅μ΄, μμ΄, μν λ³μλ₯Ό μ μΈ
int kor, eng, math;
//μ΄μ , νκ· μ μ μΈ
int total, avg;
//νμ μ μ μΈ
char grade;
printf("κ΅μ΄, μμ΄, μν μ±μ μ μ
λ ₯νμΈμ.: ");
scanf_s("?????????", &kor, ? ? ? ? , ? ? ? ? );
//μ΄μ μ ꡬνλ€.
total = ? ? ? ? ? ? ;
//νκ· μ ꡬνλ€.
avg = ? ? ? ? ;
if (avg >= 90) {
grade = 'A';
}
else if (avg ? ? ? ? ) //80μ΄μμ΄λ©΄ Bλ₯Ό μ£Όκ³
else if (avg ? ? ? ? ) //70μ΄μμ΄λ©΄ Cλ₯Ό μ£Όκ³
else if (avg ? ? ? ? ) //60μ΄μμ΄λ©΄ Dλ₯Ό μ£Όκ³
else //60λ―Έλ§μ΄λ©΄ Fλ₯Ό μ€λ€.
//κ΅μ΄, μμ΄, μν, μ΄μ , νκ· , νμ μ μΆλ ₯νμμ€.
printf(? ? ? ? ? ? );
printf(? ? ? ? ? ? );
printf(? ? ? ? ? ? );
printf(? ? ? ? ? ? );
printf(? ? ? ? ? ? );
printf(? ? ? ? ? ? );
return 0;
}
β
β
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
β
//202003327 μνμ£Ό
β
int main(void) {
int kor, eng, math;
int total;
int avg;
char grade;
β
printf("κ΅μ΄, μμ΄, μν μ±μ μ μ
λ ₯νμΈμ. : ");
scanf_s("%d %d %d", &kor, &eng, &math);
β
total = kor + eng + math;
avg = total / 3;
β
if (avg >= 90)
{
grade = 'A';
}
else if (90 > avg && 80 <= avg) grade = 'B';
else if (80 > avg && 70 <= avg)grade = 'C';
else if (70 > avg && 60 <= avg) grade = 'D';
else grade = 'F';
β
β
printf("κ΅μ΄ μ μ : %d\n", kor);
printf("μμ΄ μ μ : %d\n", eng);
printf("μν μ μ : %d\n", math);
printf("μ΄μ : %d \n", total);
printf("νκ· : %d \n", avg);
printf("νμ : %c \n", grade);
β
β
return 0;
}
//μμ
4. μμ 2-6 μ¬λ¬ κ°μ μμ μ§μ μ μ¬μ©νκΈ°λ₯Ό μμ±νμ¬ κ²°κ³Όλ₯Ό μΆλ ₯νμμ€.
β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
char name[20];
int age;
char gender;
printf("μ΄λ¦, λμ΄, μ±λ³(M/F) μμΌλ‘ μ
λ ₯νμΈμ ^^*. \n");
scanf("%s %d %c", name, &age, &gender);
printf("μ΄λ¦ : %s\n", name);
printf("μ΄λ¦ : %d\n", age);
printf("μ΄λ¦ : %c\n", gender);
return 0;
3. μμ 2-5 μ
λ ₯λ°μ 10μ§μ μ μλ₯Ό 16μ§μλ‘ λ³νν΄μ μΆλ ₯νμμ€.
β
β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
int num;
printf("μ μ? ");
scanf("%d", &num);
printf(" 10μ§μ %dλ 16μ§μ %xμ
λλ€.\n", num, num);
return 0;
}
2. μμ 2-4 μ λ°λ μ§μ νκΈ°λ₯Ό μμ±νμ¬ κ²°κ³Όλ₯Ό μΆλ ₯νμμ€.
β
#include<stdio.h>
int main()
{
float x;
x = 12.34567;
printf("%f\n", x);
printf("%.2f\n", x);
printf("%8.2f\n", x);
return 0;
}
1. μμ 2-3 λ¬Έμ ν μ§μ νκΈ°λ₯Ό μμ±νμ¬ κ²°κ³Όλ₯Ό μΆλ ₯νμμ€.
β
#include<stdio.h>
int main()
{
int num = 12345;
printf("%d\n", num);
printf("%d\n", num * 10);
printf("%d\n", num * 100);
printf("%d\n", num * 1000);
printf("%8d\n", num);
printf("%8d\n", num * 10);
printf("%8d\n", num * 100);
printf("%8d\n", num * 1000);
printf("%8d\n", num * 100000);
printf("%08d\n", num);
return 0;
}β
/λ³μ
#define _CRT_SECURE_NO_WARNINGS
//#define PI 3.14
#include<stdio.h>
int main(void) {
int first;
int second;
? ? ? ? ? ? ? ? ? ? ? ;//λμμ ν©μ μ μ₯νλ λ³μ μ μΈ
? ? ? ? ? ? ? ? ? ? ? ;//λμμ μ°¨λ₯Ό μ μ₯νλ λ³μ μ μΈ
? ? ? ? ? ? ? ? ? ? ? ;//λμμ κ³±μ μ μ₯νλ λ³μ μ μΈ
? ? ? ? ? ? ? ? ? ? ? ;//λμμ λͺ«μ μ μ₯νλ λ³μ μ μΈ
printf("첫λ²μ§Έ μλ ?");
scanf_s("???", &first);
printf("λλ²μ§Έ μλ ?");
scanf_s("???", ?????);
? ? ? = first + second;
? ? ? = first - second;
? ? ? = first * second;
? ? ? = first / second;
printf("λμμ ν© = ???", hap);
printf("λμμ μ°¨ = ???", cha);
printf("λμμ κ³± = ???", gop);
printf("λμμ λͺ« = ???", mok);
return 0;
}
//μ΅λκ°
#include<stdio.h>
//λ°°μ΄ ν¬κΈ°λ 맀ν¬λ‘ μμλ‘ μ μ
#define length 5
int main(void) {
//num λ°°μ΄ μμ±, μ΄κΈ°μΉ κ°μ 1,2,3,4,5λ‘ μ
ν
int num[length] = {3,4,7,8,14};
int max=0;
int i;
//ν΄λΉ λ°°μ΄μ μ«μλ€μ λΉκ΅ν΄μ μ΅λκ°μ κ³ λ₯Έλ€.
for (i =0; i < length; i++) {
if (max < num[i])
max = num[i];
}
//λ°°μ΄ μμλ€μ μΆλ ₯νλ€.
for (i = 0; i < length; i++)
printf("num[%d] = %d\n", i, num[i]);
printf("μ΅λκ° = %d", max);
return 0;
}
β Cνλ‘κ·Έλ¨ κ°λ° κ³Όμ
1. μμ€νμΌ μμ±
2. μ μ²λ¦¬κΈ°
3. μ»΄νμΌ(ꡬ문λΆμ, μ½λμμ±, λ§ν¬) - μ»΄νμΌμλ¬
4. λ§ν¬ (λ§μ»€) - λ§ν¬μλ¬
5. μ€ν - μ€νμλ¬
β
β λ¨μΆν€
μνλ‘μ νΈ Ctrl + Shift + N
μ€ν Ctrl + F5
β
λ¬Έμμ μ
#include <stdio.h>
void Pr_ch(void);
int main(void) {
char input;
int n = 0;
printf("λ¬Έ> λ¬Έμμ νμ(μ μ) μ
λ ₯: ");
scanf_s("%c %d", &input, sizeof(input), &n);
Pr_ch(input, n);
return 0;
}
void Pr_ch(char ch, char num) {
int i;
printf("λ΅>");
for(i = 1; i <= num; i++)
printf(" %c", ch);
printf(" : %dν μΆλ ₯ μλ£\n", i - 1);
}
//λμ
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("1~45 μ€μμ μ«μ 6κ° μΆλ ₯ \n");
printf("rand() : ");
for (int i = 1; i <= 6; i++)
printf(" %d ", rand()); //μμ λμ 6κ°κ° μΆλ ₯
printf("\n");
printf("rand() %% 45: ");
for (int i = 1; i <= 6; i++)
printf(" %d ", (rand() % 45)); //μμμ λμ 5κ° 45λ‘ λλ μ«μ 6κ°λ₯Ό μΆλ ₯ (0~44μ¬μ΄μ κ° μΆλ ₯)
printf("\n");
printf("1 + rand() %% 45) : ");
for (int i = 1; i <= 6; i++)
printf(" %d ", 1 + (rand() % 45)); //1μμ 45μ¬μ΄μ κ° μΆλ ₯
printf("\n");
return 0;
}
//λμ΄κ³μ°
#include <stdio.h>
#include <math.h>
int main(void) {
double result, age1, age2;
printf("λ΄ λμ΄ μ
λ ₯: ");
scanf_s("%lf", &age1);
printf("μ μλ λμ΄ μ
λ ₯ : ");
scanf_s("%lf", &age2);
result = age1 - age2;
printf("\n %.01fμΈ - %.01fμΈ = %3.01fμΈ\n", age1, age2, result);
result = fabs(age1 - age2); //μ λμΉ κ΅¬νλ λΌμ΄λΈλ¬λ¦¬ ν¨μ νΈμΆνκ±°μ
printf("μ λκ° %0.1fμΈ - %.01fμΈ = %3.01fμΈ", age1, age2, result);
return 0;
}
//μ΅μκ°
#include<stdio.h>
//λ°°μ΄ ν¬κΈ°λ 맀ν¬λ‘ μμλ‘ μ μ
#define length 5
int main(void) {
//num λ°°μ΄ μμ±, μ΄κΈ°μΉ κ°μ 1,2,3,4,5λ‘ μ
ν
int num[length] = { 3,4,7,8,14 };
int min = num[0];
int i;
//ν΄λΉ λ°°μ΄μ μ«μλ€μ λΉκ΅ν΄μ μ΅λκ°μ κ³ λ₯Έλ€.
for (i = 0; i < length; i++) {
if (min > num[i])
min = num[i];
}
//λ°°μ΄ μμλ€μ μΆλ ₯νλ€.
for (i = 0; i < length; i++)
printf("num[%d] = %d\n", i, num[i]);
printf("μ΅μκ° = %d", min);
return 0;
}
#include <stdio.h>
β
int main() {
β
β
char a[100];
char b[100];
char c[100];
char d_str[100];
char e[100];
β
int n = 0;
int x = 0;
β
scanf_s("%s",e); //scanf :: νμμ λ§κ² μ
λ ₯λ°μ (μ
λ ₯) **λ¬Έμ₯μ λ€ λͺ»μ½μ
β
fgets(a, sizeof(a), stdin); // fgets ::νμ€μλ¬Έμμ΄λ°μμ€κ³ +μ€λ°κΏλ¬Έμμ μ₯ (μ
λ ₯)β
printf(a); (μΆλ ₯)
gets_s(b, sizeof(b)); //gets_s :: νμ€μλ¬Έμμ΄λ°μμ€κ³ +μ€λ°κΏXXX (μ
λ ₯)β
printf(b); //pirntf :: μ€λ°κΏλ¬Έμ μλμ
λ ₯ ν μΆλ ₯ (μΆλ ₯)β
puts("hello"); // puts :: μ€λ°κΏλ¬Έμ μλμΆλ ₯ (μΆλ ₯)β
β
sscanf(c, "%d", &n);// cμ μ μ%d λ₯Ό μ½μ΄μ %xμ μ μ₯ (μ
λ ₯)ββ
int h=0, m=0, s=0;
β
sprintf(d_str, "%02d:%02d:%02d", h, m, s); // sprintf :: νμλ¬Έμμ΄μ λ°λΌ λ¬Έμμ΄ μμ± ν λ²νΌμ μ μ₯ (μ
λ ₯)ββ
puts(d_str); (μΆλ ₯)ββ
β
}β
β
=====================
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
β
int main() {
β
char s1[100] = "hello";
char s2[100] = "test";
β
printf("λ¬Έμμ΄ s1μ μ
λ ₯νμΈμ");
scanf("%s",s1);
gets(s1);
β
printf("λ¬Έμμ΄ s2μ μ
λ ₯νμΈμ");
scanf("%s",s2);
gets(s2);
β
printf("볡μ¬μ s1 = %s\n", s1);
printf("볡μ¬μ s2 = %s\n", s2);
puts(s1);
puts(s2);
β
strcpy(s2, s1); // s1μ s2λ‘ λ³΅μ¬νλ€.
β
printf("s1μ κΈΈμ΄λ %d\n", strlen(s1));
printf("s2μ κΈΈμ΄λ %d\n", strlen(s2));
β
printf("볡μ¬ν s1 = %s\n", s1);
printf("볡μ¬ν s2 = %s\n", s2);
β
strcat(s2, s1); //s2μ s1μ λΆμΈλ€.
β
printf("μ°κ²°ν s1 = %s\n", s1);
printf("μ°κ²°ν s2 = %s\n", s2);
β
if (strcmp(s1, s2) == 0) //λ¬Έμμ΄λΉκ΅ κ°μΌλ©΄ 0, μΌμͺ½μ΄ν¬λ©΄ μμ
printf("s1μ s2μ λ¬Έμμ΄ κ°μ΄ κ°λ€\n");
else
printf("s1μ s2μ λ¬Έμμ΄ κ°μ΄ λ€λ₯΄λ€\n");
β
β
β
return 0;
}β
β
β
β
=============
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
β
int main() {
β
char s1[100] = "";
char s2[100] = "";
β
char *p = NULL;
β
printf("λ¬Έμμ΄ s1μ μ
λ ₯νμΈμ");
gets(s1);
β
printf("λ¬Έμμ΄ s2μ μ
λ ₯νμΈμ");
gets(s2);
β
puts(s1);
puts(s2);
β
p = strchr(s1, '.'); //νΉμ μμΉ λ¦¬ν΄
β
β
printf("pκ° κ°λ¦¬ν€λ κ³³ = %s", p);// μ°ΎμμμΉμ£Όμ 리ν΄νκ³ κ·Έ μ΄νκ°μΆλ ₯νλ―λ‘
β
β
β
β
return 0;
}β
β
==========
β
char s1[100] = "test.txt";
char s2[100] = "010-1234-5678";
β
char *p = NULL;
β
β
p = strchr(s1, '.'); //νΉμ μμΉ λ¦¬ν΄
β
p = strtok(s1, '.');
β
p = strtok(s2, "-");
printf("κ΅λ²: %s\n", p);
p = strtok(NULL, "-");
printf("μμ리: %s\n",p);
p = strtok(NULL, "-");
printf("λ·μ리: %s\n", p);
printf("pκ° κ°λ¦¬ν€λ κ³³ = %s", p);// μ°ΎμμμΉμ£Όμ 리ν΄νκ³ κ·Έ μ΄νκ°μΆλ ₯νλ―λ‘
β==============
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
β
int main() {
β
char s1[100] = "test.txt";
char s2[100] = "HELLO";
β
β
for (int i = 0; i < strlen(s1); i++) {
s1[i] = toupper(s1[i]);
}
printf("μλ¬Έμμμ λλ¬Έμλ‘ s1 = %s\n", s1);
β
for (int i = 0; i < strlen(s2); i++) {
s2[i]=tolower(s2[i]);
}
printf("μλ¬Έμμμ λλ¬Έμλ‘ s2 = %s\n", s2);
β
β
return 0;
}β
β
β
===============
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include <string.h>
int count_space(const char *s);
β
int main() {
char str[64] = "this program\ttests const pointer to string\n"; // \tνν€, \nλ¬Έμ 곡백
puts(str);
printf("곡백문μμ κ°μ : %d\n", count_space(str));
β
return 0;
}
β
int count_space(const char* s) {
int count = 0;
while (s[0] != '\0') {
if (isspace(s[0]))
count++;
s++;
}
return count;
}β
===============β
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include <string.h>
β
#define SIZE 128
β
int swap_string(char*lhs, char* rhs, int size);
β
int main() {
char str1[SIZE] = "";
β
char str2[SIZE] = "";
printf("λ¬Έμμ΄ 2κ°? ");
scanf("%s %s", str1, str2);
β
printf("<<κ΅νμ >> str1=%s, str2=%s \n", str1, str2);
β
β
swap_string(str1, str2, SIZE);
printf("<<κ΅νν>> str1=%s, str2=%s \n", str1, str2);
β
β
return 0;
}
β
int swap_string(char*lhs, char* rhs, int size)
{
int lhs_len = strlen(lhs);
β
int rhs_len = strlen(rhs);
β
char temp[SIZE] = "";
β
if (lhs_len + 1 > size || rhs_len + 1 > size)
return 0;
β
strcpy(temp, lhs);
strcpy(lhs, rhs);
strcpy(rhs, temp);
β
return 1;
β
β
}β
==============
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include <string.h>
β
#define SIZE 128
β
int main() {
β
β
char books[5][30] = { "wonder",
"me before you",
"the honger game",
"twilight",
"harry potter",
};
β
int i = 0;
β
puts("<<λ³κ²½μ >>");
for (i = 0; i < 5; i++) {
printf("μ±
μ λͺ© : %s\n", books[i]);
}
β
for (i = 0; i < 5; i++) {
if (islower(books[i][0])) {
books[i][0] = toupper(books[i][0]);
}
}
β
puts("<<λ³κ²½ν>>");
for (i = 0; i < 5; i++)
printf("μ±
μ λͺ© : %s\n", books[i]);
β
return 0;
}β
====
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include <string.h>
β
#define SIZE 128
β
int main() {
β
β
char books[5][30] = { "wonder",
"me before you",
"the honger game",
"twilight",
"harry potter",
};
β
int i = 0;
β
puts("<<λ³κ²½μ >>");
for (i = 0; i < 5; i++) {
printf("μ±
μ λͺ© : %s\n", books[i]);
}
β
for (i = 0; i < 5; i++) {
if (islower(books[i][0])) {
books[i][0] = toupper(books[i][0]);
}
}
β
puts("<<λ³κ²½ν>>");
for (i = 0; i < 5; i++)
printf("μ±
μ λͺ© : %s\n", books[i]);
β
β
printf("books μ κΈΈμ΄ :: %d", strlen(books[1]));
for (i = 0; i <= 12; i++) {
books[4][i] = toupper(books[4][i]);
}
printf("λ§μ§λ§ μ±
: %s \n",books[4]);
β
β
return 0;
}β
======
β
#define CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
β
#define MAX 6
#define BUF_SZ 30
β
int swap_string(char* lhs, char*rhs, int size);
β
int main() {
β
β
char books[5][30] = { "wonder",
"me before you",
"the honger game",
"twilight",
"harry potter",
};
β
//int i = 0;
β
//puts("<<λ³κ²½μ >>");
//for (i = 0; i < 5; i++) {
// printf("μ±
μ λͺ© : %s\n", books[i]);
//}
β
//for (i = 0; i < 5; i++) {
// if (islower(books[i][0])) {
// books[i][0] = toupper(books[i][0]);
// }
//}
β
//puts("<<λ³κ²½ν>>");
//for (i = 0; i < 5; i++)
// printf("μ±
μ λͺ© : %s\n", books[i]);
β
β
// printf("books μ κΈΈμ΄ :: %d", strlen(books[1]));
//
// for (i = 0; i <= 12; i++) {
// books[4][i] = toupper(books[4][i]);
// }
// printf("λ§μ§λ§ μ±
: %s \n",books[4]);
int i, j;
int index;
β
puts("<<μ λ ¬ μ >>");
for (i = 0; i < MAX; i++) {
index = i;
β
for (j = i + 1; j < MAX; j++) {
if (strcmp(books[index], books[j]) > 0)
index = j;
β
}
if (i != index) {
swap_string(books[index], books[i], BUF_SZ);
}
}
β
puts("<<μ λ ¬ ν>>");
for (i = 0; i < MAX; i++) {
puts(books[i]);
β
}
β
return 0;
}
β
int swap_string(char* lhs, char*rhs, int size) {
β
β
int lhs_len = strlen(lhs);
int rhs_len = strlen(rhs);
char temp[BUF_SZ] = "";
β
if (lhs_len + 1 > size || rhs_len + 1 > size)
return 0;
β
strcpy(temp, lhs);
strcpy(lhs, rhs);
strcpy(rhs, temp);
β
return 1;
}β
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
β
int main() {
const char* str_menu[] = {
"λλ΄κΈ°", "μ νλ‘μ νΈ", "νλ‘μ νΈ μ΄κΈ°", "μ루μ
λΉλ", "λλ²κΉ
μμ"
};
int sz_menu = sizeof(str_menu) / sizeof(str_menu[0]);
int menu;
while (1) {
int i;
for (i = 0; i < sz_menu; i++)
printf("%d.%s\n", i, str_menu[i]);
printf("λ©λ΄ μ ν? ");
scanf("%d", &menu);
if (menu == 0)
break;
else if (menu > 0 && menu < sz_menu)
printf("%s λ©λ΄λ₯Ό μ ννμ΅λλ€.\n\n", str_menu[menu]);
else
printf("μλͺ» μ ννμ΅λλ€.\n\n");
}
return 0;
}β
β
--
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h>
int main() {
char str_menu[5][20];
int sz_menu = sizeof(str_menu) / sizeof(str_menu[0]);
int menu; int i;
for (i = 0; i < 5; i++) {
printf("λ©λ΄λͺ
μ μ
λ ₯νμμ€");
scanf("%s", str_menu[i]);
}
while (1) {
int i;
for (i = 0; i < sz_menu; i++)
printf("%d.%s\n", i, str_menu[i]);
printf("λ©λ΄ μ ν? ");
scanf("%d", &menu);
if (menu == 0)
break;
else if (menu > 0 && menu < sz_menu)
printf("%s λ©λ΄λ₯Ό μ ννμ΅λλ€.\n\n", str_menu[menu]);
else
printf("μλͺ» μ ννμ΅λλ€.\n\n");
}
return 0;
}β
β
---
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
β
int main() {
const char* str_menu[5][20];
int sz_menu = sizeof(str_menu) / sizeof(str_menu[0]);
int menu = 0;
β
//λ©λ΄λͺ
μ ν€λ³΄λλ‘ μ
λ ₯λ°κΈ°
//λ¬Έμμ΄λ°°μ΄μ μ μ₯
β
β
printf("λ©λ΄ μ΄λ¦ μ μ΄μ£ΌμΈμ");
for (int i =0; i< sz_menu; i++)
scanf("%s", str_menu[sz_menu]);
β
while (1) {
int i;
β
printf("λ©λ΄ μ ν? ");
scanf("%d", &menu);
β
if (menu == 0)
break;
β
else if (menu > 0 && menu < sz_menu)
printf("%s μ ννμ΅λλ€.\n\n", str_menu[menu]);
β
else
printf("μλͺ» μ ννμ΅λλ€.\n\n");
}
return 0;
}β
------------
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
β
int main() {
char s1[] = "100";
char s2[] = "12.93";
char buffer[100];
β
β
int i;
double d;
double result;
β
//λ¬Έμμ΄ s1μ μ μλ‘ λ³ννλ€.
β
i = atof(s1); // λ¬Έμμ΄ > μ μλ‘ λ³ννλ ν¨μ
d = atof(s2);
β
result = i + d;
β
sprintf(buffer, "%f", result);
printf("μ°μ°κ²°κ³Όλ %s μ
λλ€. \n", buffer);
β
return 0;
}β
β
----------------
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define SIZE 100
β
int main() {
β
char str[SIZE];
int count = 0;
β
scanf("%s", str);
β
for (int i = 0; i < SIZE; i++) {
// ispunct()
if (str[i]=='.')
count++;
}
β
printf("ꡬλμ μ κ°μλ %d κ° μ
λλ€.", count);
β
β
return 0;
}β
---------------------------
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define SIZE 100
β
int count_period(const char* s);
β
int main() {
β
char str[SIZE];
int count = 0;
printf("λ¬Έμμ΄μ μ
λ ₯λ°λλ€.");
scanf("%s", str);
printf("%s\n", str);
β
β
//for (int i = 0; i < SIZE; i++) {
// // ispunct()
// if (str[i]=='.')
// count++;
//}
β
printf("ꡬλμ μ κ°μλ %d κ° μ
λλ€.", count_period(str));
β
return 0;
}
β
int count_period(const char* s) {
int count = 0;
while (s[0] != '\0') {
if (ispunct(s[0]))
count++;
s++;
}
β
return count;
}
β
β-------------------------
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define SIZE 100
β
int count_period(const char* s);
β
int main() {
β
char str[SIZE];
int count = 0;
printf("λ¬Έμμ΄μ μ
λ ₯λ°λλ€.");
/* scanf("%s", str);*/
gets(str);
printf("%s\n", str);
β
β
//for (int i = 0; i < SIZE; i++) {
// // ispunct()
// if (str[i]=='.')
// count++;
//}
β
printf("ꡬλμ μ κ°μλ %d κ° μ
λλ€.", count_period(str));
β
return 0;
}
β
int count_period(const char* s) {
int count = 0;
while (s[0] !='\0') {
if (ispunct(s[0]))
count++;
s++;
}
β
return count;
}
--------------------------------------
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define SIZE 100
β
int main() {
char str[SIZE];
int count = 0;
printf("λ¬Έμμ΄μ μ
λ ₯λ°λλ€.");
gets(str);
printf("%s\n", str);
β
β
for (int i = 0; i < strlen(str); i++) {
if (ispunct(str[i]))
count++;
}
β
printf("ꡬλμ μ κ°μλ %d κ° μ
λλ€.", count);
β
return 0;
}
β
------------------------------------------
β
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define SIZE 100
β
β
struct contact
{
char name[20];
char phone[20];
int ringtone;
};
int main() {
β
printf("%d", sizeof(struct contact));
β
return 0;
}
ββ
-------------------------------
#include<Stdio.h>
struct contact
{
char name[20];
char phone[20];
int ringtone;
};
int main(void) {
struct contact ct = { "κΉμμ§","0110101003",0 };
struct contact ct1 = { 0 }, ct2 = { 0 };
ct.ringtone = 1;
strcpy(ct.phone,"010123415");
printf("μ΄λ¦: %s\n", ct.name);
printf("μ νλ²νΈ: %s\n", ct.phone);
printf("벨μ리: %d\n", ct.ringtone);
return 0;
}β
β
β
β
-------
β
#include<Stdio.h>
struct contact
{
char name[20];
char phone[20];
int ringtone;
};
int main(void) {
struct contact ct = { "κΉμμ§","0110101003",0 };
struct contact ct1 = { 0 }, ct2 = { 0 };
β
ct.ringtone = 1;
strcpy(ct.phone, "010123415");
printf("μ΄λ¦: %s\n", ct.name);
printf("μ νλ²νΈ: %s\n", ct.phone);
printf("벨μ리: %d\n", ct.ringtone);
β
strcpy(ct1.name, "μνμ£Ό");
strcpy(ct1.phone, "01054625192");
ct1.ringtone = 324;
printf("μ΄λ¦: %s\n", ct1.name);
printf("μ νλ²νΈ: %s\n", ct1.phone);
printf("벨μ리: %d\n", ct1.ringtone);
β
return 0;
}β
β
--------------
#define _CRT_SECURE_NO_WARNINGS
#include<Stdio.h>
struct contact
{
char name[20];
char phone[20];
int ringtone;
};
int main(void) {
struct contact ct = { "κΉμμ§","0110101003",0 };
struct contact ct1 = { 0 }, ct2 = { 0 };
β
ct.ringtone = 1;
strcpy(ct.phone, "010123415");
printf("μ΄λ¦: %s\n", ct.name);
printf("μ νλ²νΈ: %s\n", ct.phone);
printf("벨μ리: %d\n", ct.ringtone);
β
strcpy(ct1.name, "μνμ£Ό");
strcpy(ct1.phone, "01054625192");
ct1.ringtone = 324;
printf("μ΄λ¦: %s\n", ct1.name);
printf("μ νλ²νΈ: %s\n", ct1.phone);
printf("벨μ리: %d\n", ct1.ringtone);
β
printf("μ΄λ¦:\n");
scanf("%s", ct2.name);
printf("μ νλ²νΈ:\n");
scanf("%s", ct2.phone);
printf("벨μ리:\n");
scanf("%d", &ct2.ringtone);
β
printf("μ΄λ¦: %s\n", ct2.name);
printf("μ νλ²νΈ: %s\n", ct2.phone);
printf("벨μ리: %d\n", ct2.ringtone);
β
β
β
return 0;
}β
--------------β
β
#define _CRT_SECURE_NO_WARNINGS
#include<Stdio.h>
struct student
{
char name[20];
char phone[20];
int age;
char addr[50];
β
};
int main(void) {
struct student s1, s2, s3;
β
β
strcpy(s1.name, "μνμ£Ό");
strcpy(s1.phone, "01054625192");
s1.age = 20;
strcpy(s1.addr, "μμΈμ μ€λꡬ λ©΄λͺ©λ");
β
printf("μ΄λ¦: %s\n", s1.name);
printf("μ νλ²νΈ: %s\n", s1.phone);
printf("λμ΄: %d\n", s1.age);
printf("μ£Όμ: %s\n", s1.addr);
β
β
β
return 0;
}β
-------------------------
β
β
#define _CRT_SECURE_NO_WARNINGS
#include<Stdio.h>
#include<stdint.h>
β
struct sungjuk
{
int kor;
int eng;
int math;
double total;
double avg;
β
};
int main(void) {
struct sungjuk s1 = { 0 };
β
printf("κ΅μ΄:\n");
scanf("%d", &s1.kor);
β
printf("μν:\n");
scanf("%d", &s1.math);
β
printf("μμ΄:\n");
scanf("%d", &s1.eng);
β
s1.total = s1.kor + s1.math + s1.eng;
s1.avg = s1.total / 3;
β
printf("κ΅μ΄: %d\n", s1.kor);
printf("μν: %d\n", s1.math);
printf("μμ΄: %d\n", s1.eng);
printf("μ΄μ : %f\n", s1.total);
printf("νκ· : %f\n", s1.avg);
β
β
β
return 0;
}β
------------------------
#define _CRT_SECURE_NO_WARNINGS
#include<Stdio.h>
#include<stdint.h>
β
struct sungjuk
{
int kor;
int eng;
int math;
double total;
double avg;
char grade;
β
};
int main(void) {
struct sungjuk s1 = { 0 };
β
printf("κ΅μ΄:\n");
scanf("%d", &s1.kor);
β
printf("μν:\n");
scanf("%d", &s1.math);
β
printf("μμ΄:\n");
scanf("%d", &s1.eng);
β
s1.total = s1.kor + s1.math + s1.eng;
s1.avg = (double) s1.total / 3;
β
if (s1.avg >= 90 && s1.avg <= 100)
s1.grade = 'A';
else if (s1.avg>=80 && s1.avg<=89)
s1.grade = 'B';
else if (s1.avg >= 70 && s1.avg <= 70)
s1.grade = 'C';
else if (s1.avg >= 60 && s1.avg <= 69)
s1.grade = 'D';
else
s1.grade = 'F';
β
β
β
printf("κ΅μ΄: %d\n", s1.kor);
printf("μν: %d\n", s1.math);
printf("μμ΄: %d\n", s1.eng);
printf("μ΄μ : %f\n", s1.total);
printf("νκ· : %f\n", s1.avg);
printf("νμ : %c\n", s1.grade);
β
β
return 0;
}β
β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
struct Student
{
char name[20];
char phone[20];
int age;
char addr[150];
};
β
int main() {
struct Student s;
/*strcpy(s.name, "μ€μΈμ±");
strcpy(s.phone, "010-8725-0916");
s.age = 20;
strcpy(s.addr, "μμΈμ μ‘νꡬ λ°©μ΄λ");*/
printf("μ΄λ¦μ?");
gets(s.name);
printf("μ νλ²νΈλ?");
gets(s.phone);
printf("μ£Όμλ?");
gets(s.addr);
printf("λ μ΄?");
scanf("%d", &s.age);
β
β
printf("μ΄ λ¦: %s\n", s.name);
printf("μ νλ²νΈ: %s\n", s.phone);
printf("λμ΄: %d\n", s.age);
printf("μ£Όμ: %s\n", s.addr);
return 0;
}β
--------------------------------------
β
struct Circle
{
double x;
double y;
double radius;
};
β
int main() {
struct Circle c;
c.x = 5;
c.y = 4;
c.radius = 10;
β
printf("μμ xμ’ν: %1.f\n", c.x);
printf("μμ yμ’ν: %1.f\n", c.y);
printf("μμ λ°μ§λ¦: %1.f\n", c.radius);
β
return 0;
}β
β
--------------------------------------
ββ
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
struct Circle
{
int x;
int y;
double radius;
};
β
int main() {
struct Circle c;
c.x = 5;
c.y = 4;
c.radius = 10;
β
struct Circle c1;
printf("x\n");
scanf("%d",&c1.x);
printf("y\n");
scanf("%d",&c1.y);
printf("λ°μ§λ¦\n");
scanf("%lf", &c1.radius);
β
printf("μμ xμ’ν: %d\n", c.x);
printf("μμ yμ’ν: %d\n", c.y);
printf("μμ λ°μ§λ¦: %1.f\n", c.radius);
printf("μμ xμ’ν: %d\n", c1.x);
printf("μμ yμ’ν: %d\n", c1.y);
printf("μμ λ°μ§λ¦: %1.f\n", c1.radius);
return 0;
}β
--------------------------------------β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
struct Circle
{
int x;
int y;
int radius;
double circum; //λλ
double area; //λ©΄μ
};
β
int main() {
struct Circle c;
c.x = 5;
c.y = 4;
c.radius = 10;
c.circum = 2*3.14*c.radius;
c.area = 3.14*c.radius*c.radius;
β
struct Circle c1;
printf("x\n");
scanf("%d",&c1.x);
printf("y\n");
scanf("%d",&c1.y);
printf("λ°μ§λ¦\n");
scanf("%d", &c1.radius);
c1.circum = 2 * 3.14 * c1.radius;
c1.area = 3.14 * c1.radius * c1.radius;
β
printf("μμ xμ’ν: %d\n", c.x);
printf("μμ yμ’ν: %d\n", c.y);
printf("μμ λ°μ§λ¦: %d\n", c.radius);
printf("μλλ : %.2f\n", c.circum);
printf("μλ©΄μ : %.2f\n", c.area);
β
printf("μμ xμ’ν: %d\n", c1.x);
printf("μμ yμ’ν: %d\n", c1.y);
printf("μμ λ°μ§λ¦: %d\n", c1.radius);
printf("μλλ : %.2f\n", c1.circum);
printf("μλ©΄μ : %.2f\n", c1.area);
β
return 0;
}β
--------------------------------------β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
struct Circle
{
int x;
int y;
int radius;
double circum; //λλ
double area; //λ©΄μ
};
β
int main() {
struct Circle c[3];
β
for (int i = 0; i < 3; i++) {
printf("x\n");
scanf("%d", &c[i].x);
printf("y\n");
scanf("%d", &c[i].y);
printf("λ°μ§λ¦\n");
scanf("%d", &c[i].radius);
c[i].circum = 2 * 3.14 * c[i].radius;
c[i].area = 3.14 * c[i].radius * c[i].radius;
}
β
for (int i = 0; i < 3; i++) {
printf("%dλ²μ§Έ μμ xμ’ν: %d\n",i, c[i].x);
printf("%dλ²μ§Έ μμ yμ’ν: %d\n", i, c[i].y);
printf("%dλ²μ§Έ μμ λ°μ§λ¦: %d\n", i, c[i].radius);
printf("%dλ²μ§Έ μλλ : %.2f\n", i, c[i].circum);
printf("%dλ²μ§Έ μλ©΄μ : %.2f\n", i, c[i].area);
}
β
return 0;
}β
β
--------------------------------------β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
struct Sungjuk
{
char name[20];
int kor;
int eng;
int math;
double total;
double avg;
};
β
int main() {
struct Sungjuk s[3]; //μΈμ€ν΄μ€
β
for (int i = 0; i < 3; i++) {
printf("μ΄λ¦\n");
scanf("%s", &s[i].name);
printf("κ΅μ΄\n");
scanf("%d", &s[i].kor);
printf("μμ΄\n");
scanf("%d", &s[i].eng);
printf("μν\n");
scanf("%d%*c", &s[i].math);
s[i].total = s[i].kor + s[i].eng + s[i].math;
s[i].avg = (double)s[i].total / 3;
printf("-----");
}
β
for (int i = 0; i < 3; i++) {
printf("%dλ²μ§Έ μ΄λ¦: %s\n",i, s[i].name);
printf("%dλ²μ§Έ κ΅μ΄: %d\n", i, s[i].kor);
printf("%dλ²μ§Έ μμ΄: %d\n", i, s[i].eng);
printf("%dλ²μ§Έ μν: %d\n", i, s[i].math);
printf("%dλ²μ§Έ μ΄μ : %.2f\n", i, s[i].total);
printf("%dλ²μ§Έ νκ· : %.2f\n", i, s[i].avg);
printf("-----\n");
}
β
return 0;
}β
--------------------------------------ββ
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
typedef struct contact
{
char name[20];
char phone[20];
int ringtone;
}CONTACT;
β
int main() {
CONTACT arr[] = {
{"κΉμμ§","000-0000-0000",0},
{"μ μ κ΅","000-0000-0000",0},
{"λ°μ§λ―Ό","000-0000-0000",0},
{"κΉλ¨μ€","000-0000-0000",0},
{"λ―Όμ€κΈ°","000-0000-0000",0},
{"μ νΈμ","000-0000-0000",0},
{"κΉνν","000-0000-0000",0}
};
int size = sizeof(arr) / sizeof(arr[0]);
int i;
char name[20];
int index;
printf("κ²μν μ΄λ¦μ?");
scanf("%s", name);
index = -1;
for (int i = 0; i < size; i++) {
if (strcmp(arr[i].name, name) == 0) {
index = i;
break;
}
}
β
if (index >= 0) {
printf("%sμ μ νλ²νΈ : %s\n", arr[index].name, arr[index].phone);
}
else {
printf("μ°Ύμμμμ");
}
β
return 0;
}β
--------------------------------------ββ
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
typedef struct contact
{
char name[20];
char phone[20];
int ringtone;
}CONTACT;
β
int main() {
CONTACT ct = { "κΉμμ§","000-0000-0000",0 };
CONTACT* p = &ct;
β
strcpy(p->phone, "01012345678");
p->ringtone = 5;
β
printf("μ΄λ¦: %s\n", p->name);
printf("μ λ²: %s\n", p->phone);
printf("벨μ리: %d\n", p->ringtone);
β
return 0;
}β
--------------------------------------ββ
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
typedef struct contact
{
char name[20];
char phone[20];
int ringtone;
}CONTACT;
β
int main() {
CONTACT ct = { "κΉμμ§","000-0000-0000",0 };
CONTACT* p = &ct;
β
strcpy(p->phone, "01012345678");
β
p->ringtone = 5;
printf("μ΄λ¦\n");
scanf("%s", p->name);
printf("μ λ²\n");
scanf("%s", p->phone);
printf("벨μ리\n");
scanf("%d", &ct.ringtone);
β
β
printf("μ΄λ¦: %s\n", p->name);
printf("μ λ²: %s\n", p->phone);
printf("벨μ리: %d\n", p->ringtone);
β
return 0;
}β
--------------------------------------ββ
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
typedef struct contact
{
char name[20];
char phone[20];
int ringtone;
}CONTACT;
β
int main() {
CONTACT arr[] = {
{ "A","000-0000-0000",0 },
{ "B","000-0000-0000",0 },
{ "C","000-0000-0000",0 },
{ "D","000-0000-0000",0 },
{ "E","000-0000-0000",0 },
{ "F","000-0000-0000",0 },
};
int size = sizeof(arr) / sizeof(arr[0]);
int i;
char name[20];
int index;
CONTACT* recent = NULL;
β
while (1) {
printf("μ΄λ¦ ");
scanf("%s", name);
if (strcmp(name, ".") == 0)
break;
β
index = -1;
β
β
for (i = 0; i < size; i++) {
if (strcmp(arr[i].name, name) == 0) {
index = i;
break;
}
}
if (index >= 0) {
printf("%sμ μ νλ²νΈλ‘ %sλ‘ μ νλ₯Ό κ²λλ€\n",
arr[index].name, arr[index].phone);
recent = &arr[index];
}
else
{
printf("μ");
β
}
}
if (recent)
printf("μ΅κ·Ό ν΅ν : %s %s\n ", recent->name, recent->phone);
return 0;
}β
--------------------------------------β
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
β
struct student
{
char name[20];
char phone[20];
};
void changephone(struct student*sp);
β
int main() {
struct student s;
printf("μ΄λ¦?");
scanf("%s", s.name);
printf("μ νλ²νΈ?");
scanf("%s", s.phone);
β
printf("λ³κ²½μ μ΄λ¦ =%s \n", s.name);
printf("λ³κ²½μ μ λ² =%s \n", s.phone);
changephone(&s);
β
printf("λ³κ²½ν μ λ² =%s \n", s.phone);
return 0;
}
β
void changephone(struct student* sp) {
strcpy(sp->phone, "01054625192");
}β
β