diff options
[SP/P1] Solved all exercises
1 files changed, 29 insertions, 0 deletions
| -rw-r--r-- | Year 3/System programming/Practicum1/cut.c | 29 |
diff --git a/Year 3/System programming/Practicum1/cut.c b/Year 3/System programming/Practicum1/cut.c new file mode 100644 index 0000000..78259fa --- /dev/null +++ b/Year 3/System programming/Practicum1/cut.c @@ -0,0 +1,29 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdio.h> + +int main(int argc, char *argv[]) { + int f = open(argv[1], O_RDONLY); + if (f == -1) return 1; + + int m, n; + scanf("%d-%d", &m, &n); + + int col = 1; + char buf; + while (read(f, &buf, 1)) { + if (buf == '\n') { + col = 1; + write(0, &buf, 1); + continue; + } + if (m <= col && col <= n) { + write(0, &buf, 1); + } + col++; + } + + close(f); +} |
