0% found this document useful (0 votes)
103 views

To Implement A Simple Text Editor

The document describes the algorithm and program for implementing a simple text editor. The text editor allows the user to create a new file, open an existing file, save the current file, delete a file, and exit the program. The program uses functions like fopen(), fputs(), fgets() to perform file operations like writing, reading, and closing files. It stores file content in a 2D character array and allows the user to enter multiple lines terminated by "end".
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

To Implement A Simple Text Editor

The document describes the algorithm and program for implementing a simple text editor. The text editor allows the user to create a new file, open an existing file, save the current file, delete a file, and exit the program. The program uses functions like fopen(), fputs(), fgets() to perform file operations like writing, reading, and closing files. It stores file content in a 2D character array and allows the user to enter multiple lines terminated by "end".
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

TEXT EDITOR

Ex.no:
Date:

AIM
To implement a simple text editor

ALGORITHM

Step1: Begin.

Step2: create a new file in write mode.

Step3: write data into the file console up to end.

Step4: close file.

Step5: open file in read mode.

Step6: read data from the file up to EOF.

Step7: close file.

Step8: save the file with a valid name.

Step9: if(op==’y’||op==’Y’) then file will be saved.

Step10: if(op==’n’||op==’N’) then file will not save.

Step11: enter a file name to data.

Step12: exit from the file.

PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<dir.h>
void main()
{
FILE *fn,*fd;
char *f,line[30][60],fname[30],str[30],op;
int i,j,k,len=0,ch=1,sn,n;
clrscr();
while(ch!=0)
{
printf("\n\t\tMENU\n1.New\n2.Open\n3.Save\n4.Delete\n5.Exit\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the content and type 'end'to terminate:\n");
i=0;
j=0;
fflush(stdin);
gets(line[i]);
while(strcmp(line[i],"end")!=0)
gets(line[++i]);
--i;
break;
case 2:
printf("\nEnter the file name to open:");
scanf("%s",&fname);
if(searchpath(fname))
{
fn=fopen(fname,"r+");
while(1)
{
ch=fgetc(fn);
if(ch==EOF)
break;
else
printf("%c",ch);
}
getch();
fclose(fn);
}
else
{
printf("\nInvalid file name");
getch();
}
break;
case 3:
printf("\nEnter the file name:");
scanf("%s",&fname);
if(searchpath(fname))
{
fflush(stdin);
printf("\nExisting file overwrite it y/n?:");
fn=fopen(fname,"w");
j=0;
while(j<=1)
{
if(j==1)
{
len=strlen(line[j]);
line[j][len]='\0';
}
fputs(line[j],fn);
j++;
}
fclose(fn);
}
else
{
fn=fopen(fname,"w");
j=0;
while(j<=1)
{
if(j==1)
{
len=strlen(line[j]);
line[j][len]='\0';
}
fputs(line[j],fn);
j++;
}
fclose(fn);
}
break;
case 4:
printf("\nEnter The File Name To Delete:");
scanf("%s",&fname);
if(searchpath(fname))
{
remove(fname);
printf("\nFILE IS DELETED");
}
else
printf("\nFILE IS NOT FOUND");
break;
case 5:
exit();
break;
default:
printf("\n\tINVALID OPTION CHOOSE CORRECT OPTION");
getch();
break;
}
}
}

OUTPUT

MENU
1.New
2.Open
3.Save
4.Delete
5.Exit
Enter your choice:1

Enter the content and type 'end'to terminate:


hai welcome to ss lab
end

MENU
1.New
2.Open
3.Save
4.Delete
5.Exit
Enter your choice:3

Enter the file name:a.c

Existing file overwrite it y/n?:

MENU
1.New
2.Open
3.Save
4.Delete
5.Exit
Enter your choice:2

Enter the file name to open:a.c


hai welcome to ss labend

MENU
1.New
2.Open
3.Save
4.Delete
5.Exit
Enter your choice:4
Enter The File Name To Delete:a.c

FILE IS DELETED

MENU
1.New
2.Open
3.Save
4.Delete
5.Exit
Enter your choice:5

SNAPSHOT

You might also like