#include < stdio.h >
#include < stdlib.h >
#define MAX 50000
#define LEN 256
char text[MAX][LEN];
int main(int argc, char *argv[]) {
register int t,x,j;
FILE *outfile;
outfile = fopen(argv[1], "w+");
if (outfile == NULL) {
printf("\n\n Error Unable to open file! \n");
} if (argc <= 1) { printf("USAGE: ./editor [file name to open] \n\n"); exit(0); }
system("clear");
printf("OPEN FILE: %s \n Enter an empty line to quit. \n", argv[1]);
for(t = 0; t < MAX; t++) {
printf("%d: ", t);
gets(text[t]);
fprintf(outfile, "%s\n",text[t]);
if(!*text[t]) break;
}
system("clear");
printf("Output Saved to file %s \n Lines for review by editor: \n", argv[1]);
for(x = 0; x < t; x++) { for(j = 0; text[ x ][ j ]; j++) putchar(text[ x ][ j ]); putchar('\n'); }
fclose(outfile);
return 0;
}
Monday, May 18, 2015
Subscribe to:
Posts (Atom)