diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba2906d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +main diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6b8a04c --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +main: main.c + gcc -o main main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..e246640 --- /dev/null +++ b/main.c @@ -0,0 +1,34 @@ +#include +#include + +void edit_line(char *buffer, int current_line) { + for (int i = 0; i < current_line; i++) { + buffer = strchr(buffer, '\n') + 1; + } + + char *line_end = strchr(buffer, '\n'); + char saved[1024] = {0}; + strcpy(saved, line_end); + scanf("%s", buffer); + strcpy(buffer + strlen(buffer), saved); +} + +int main(int argc, char **argv) { + char buffer[1024] = { 0 }; + + FILE *f = fopen(argv[1], "r"); + fread(buffer, sizeof(buffer), 1, f); + fclose(f); + + printf("Contents:\n%s\n", buffer); + + int current_line = 0; + scanf("%d", ¤t_line); + edit_line(buffer, current_line); + + f = fopen(argv[1], "w"); + fwrite(buffer, strlen(buffer), 1, f); + fclose(f); + + return 0; +}