vorking #2 both guys
This commit is contained in:
19
lab_2/kirill/lib_s.c
Normal file
19
lab_2/kirill/lib_s.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stddef.h>
|
||||
|
||||
int replace_char_line(char *buf, int key, int *replacements_left) {
|
||||
(void)key;
|
||||
int replaced = 0;
|
||||
int count = 0;
|
||||
|
||||
for (size_t i = 0; buf[i] != '\0'; i++) {
|
||||
if (buf[i] == '\n') continue;
|
||||
count++;
|
||||
if (count % 3 == 0 && *replacements_left > 0) {
|
||||
buf[i] = ' ';
|
||||
replaced++;
|
||||
(*replacements_left)--;
|
||||
if (*replacements_left == 0) break;
|
||||
}
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
Reference in New Issue
Block a user