add really crappy text editor
This commit is contained in:
parent
cb07391456
commit
041cc01403
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
main
|
34
main.c
Normal file
34
main.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user