쉽게 풀어쓴 C언어 EXPRESS(개정 3판) - Chapter 12-4


13.

#include <string.h>
#include <stdio.h>

#define SIZE 100

int get_punc(char* s) {

int i;
int count = 0;

for (i = 0; i < strlen(s); i++) {

if (s[i] == ',' || s[i] == '.')

count++;

}
return count;
}

int main(void) {

char str[SIZE];

printf("문자열을 입력하시오: ");
gets(str);

printf("구두점의 개수는 %d입니다.\n", get_punc(str));
return 0;
}

14.

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main(void) {

char seps[] = " ";
char s[200], find[100], replace[100], target[200] = "";
char* token;

printf("문자열을 입력하시오: ");
gets(s);

printf("찾을 문자열: ");
gets(find);

printf("바꿀 문자열: ");
gets(replace);

token = strtok(s, seps);

if (strcmp(token, find) == 0)
strcat(target, replace); 
else
strcat(target, token);

token = strtok(NULL, seps);
}

printf("결과: %s", target);

return 0;
}

15.

#include <stdio.h>
#include <string.h>

int main(void) {

char s[100] = {

0
}

;

char op[100];

int x, y;

char* token;

printf("연산을 입력하시오:");
gets(s);

token = strtok(s, " ");

token = strtok(NULL, " ");

token = strtok(NULL, " ");

if (strcmp(op, "add") == 0) {
printf("연산의 결과: %d", x + y);
}
else if (strcmp(op, "sub") == 0) {

printf("연산의 결과: %d", x - y);
}
else if (strcmp(op, "mul") == 0) {

printf("연산의 결과: %d", x * y);
}
else if (strcmp(op, "div") == 0) {

printf("연산의 결과: %d", x / y);
}
else {

}
return 0;
}

16.

#include <stdio.h>
#include <string.h>

int main(void) {

char s[100];
int size, i, k;

puts("광고하고 싶은 텍스트를 입력하시오: ");
gets(s);

size = strlen(s);

puts("======================");

for (k = 0; k < size; k++) {
for (i = k; i < (k + size); i++) {
if (i < size)
putchar(s[i]); 
else {
putchar(s[i - size]);
}
}
putchar('\n');
}
return 0;
}

댓글

이 블로그의 인기 게시물

쉽게 풀어쓴 C언어 EXPRESS(개정 3판) - Chapter 10-3

쉽게 풀어쓴 C언어 EXPRESS(개정 3판) - Chapter 16-1

쉽게 풀어쓴 C언어 EXPRESS(개정 3판) - Chapter 13-2