finished cls06

This commit is contained in:
2026-05-25 22:45:24 +09:00
parent 494e7b51bb
commit 03fc9322f4
8 changed files with 144 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
include ../common.mk
PROJECT_NAME:=cls06
TGTS:=$(patsubst %.c,%,$(wildcard *.c))
all: $(TGTS)
%: %.c
@mkdir -p $(BUILD_PATH)/$(PROJECT_NAME)
$(CC) $(CFLAGS) $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@
clean:
$(RM) -drf $(BUILD_PATH)/$(PROJECT_NAME)
+37
View File
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#define BUFF_SZ 256
int str_chnum(const char s[], int c) {
int idx = 0;
int n = 0;
while (s[idx] != '\0' && idx < BUFF_SZ) {
if (s[idx] == (char)c) {
n++;
}
idx++;
}
return n;
}
int main(void) {
char *buff = (char*)calloc(sizeof(char), BUFF_SZ);
char query = 0;
printf("Input String: ");
fgets(buff, BUFF_SZ, stdin);
printf("Input Search Character: ");
scanf("%c", &query);
int cnt = str_chnum(buff, query);
printf("Found %d \'%c\'\n", cnt, query, buff);
free(buff);
return 0;
}
+42
View File
@@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#define BUFF_SZ 256
void put_stringn(const char s[], int n) {
if (n < 0) return;
int idx = 0;
for (int i = 0; i < n; i++) {
idx = 0;
while (s[idx] != '\0' && idx < BUFF_SZ) {
if (s[idx] == '\n') {
idx++;
continue;
}
putchar(s[idx]);
idx++;
}
}
putchar('\0');
}
int main(void) {
char *buff = (char*)calloc(sizeof(char), BUFF_SZ);
int n = 0;
printf("Input String: ");
fgets(buff, BUFF_SZ, stdin);
printf("Input Repeat Num: ");
scanf("%d", &n);
put_stringn(buff, n);
putchar('\n');
free(buff);
return 0;
}