Hi there,
I'm having a lot of trouble trying to write an apparently "simple" editor. What do you make of my code? It's already late to hand in.
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
char text[23][80];
int main() {
int i=0, num;
char c[80];
char temp[80];
FILE *g;
printf("Please enter the file name:\n");
gets(c);
g = fopen(c, "r");
if(g == NULL) {
printf("Problem! The file did not open sucessfully.");
exit(0);
}
while(fgets (text[i], 80, g) !=NULL) {
i++;
}
fclose(g);
system("cls");
for(i=0; i<23; i++) {
printf("%s", text[i]);
}
printf("Command:");
fgets(temp, sizeof(temp), stdin);
sscanf(temp, "%c %d", c, &num);
while(strcmp(temp, "Q") !=0) {
if(strcmp(temp, "R") ==0) {
fgets(text[num],80,stdin);
}
if(strcmp(temp, "D") ==0) {
for(i=21; i<num; i++) {
strcpy(text[i], text[i+1]);
}
}
if(strcmp(temp, "I") ==0) {
for(i=22; i>num; i--) {
strcpy(text[i], text[i-1]);
}
}
if(strcmp(temp, "S") ==0) {
for(i=0; i<23; i++) {
fprintf(g, text[i]);
}
}
}
}