generated from kenryuS/report-temp
finished cls06
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle}
|
||||
|
||||
\usepackage{tex/preamble}
|
||||
\usepackage{tex/simple-title}
|
||||
|
||||
\reportauthor{柴田健琉}
|
||||
\reporttitle{情報処理2 - 前期第6回課題}
|
||||
\reportdate{2026年}{05月}{25日}
|
||||
\turnindate{2026年}{05月}{25日}
|
||||
|
||||
\begin{document}
|
||||
\simpletitle
|
||||
|
||||
\section{はじめに}
|
||||
|
||||
この課題のプログラムは以下の環境での動作が確認されている:
|
||||
|
||||
\begin{itemize}
|
||||
\item {OS: NixOS 25.11 Xantusia, Linux 7.0.9 x86\_64}
|
||||
\item {CC: GCC 15.2.0}
|
||||
\item {CFLAGS: \texttt{-g -O1 -Wall -Wpedantic}}
|
||||
\end{itemize}
|
||||
|
||||
\section{課題1}
|
||||
|
||||
入力した文字列\texttt{s}内に特定の文字\texttt{c}の出現回数を返す関数\texttt{str\_chnum}を作成する.
|
||||
|
||||
\lstinputlisting[language=C,title={課題1のプログラム}]{./src/cls06/a1.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls06-a1.png}
|
||||
\caption{課題1の実行結果}
|
||||
\end{figure}
|
||||
|
||||
\section{課題2}
|
||||
|
||||
入力した文字列\texttt{s}を\texttt{n}回連続で出力するサブルーティーン\texttt{put\_stringn}を作成する.
|
||||
|
||||
\lstinputlisting[language=C,title={課題2のプログラム}]{./src/cls06/a2.c}
|
||||
|
||||
\subsection{実行結果}
|
||||
|
||||
\begin{figure}[tbh]
|
||||
\centering
|
||||
\includegraphics[width=12cm]{./assets/cls06-a2.png}
|
||||
\caption{課題2の実行結果}
|
||||
\end{figure}
|
||||
\end{document}
|
||||
@@ -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)
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user