Text editors project

14
WAP A C PROGRAM TO CREATE TEXT EDITOR WHICH CONTAIN THE WORKING OF OPEN, SAVE, NEW, EXIT AND RENAME Term paper submitted By To Department of Computer Science and Engineering In partial fulfilment of the Requirement for the CA of Linux Programming To Mr. Sir (December 2013)

description

project on text editors

Transcript of Text editors project

Page 1: Text editors project

WAP A C PROGRAM TO CREATE TEXT EDITOR WHICH CONTAIN THE WORKING OF OPEN, SAVE, NEW, EXIT AND RENAME

Term paper submitted

By

To

Department of Computer Science and Engineering

In partial fulfilment of the Requirement for the CA of Linux Programming

To

Mr. Sir

(December 2013)

CONTENTS

Page 2: Text editors project

INTRODUCTION TO TEXT EDITORS

AKNOWLEDGEMENT

ALGORITHM

SOURCE CODE

OUTPUT

CONCLUSION

REFERENCES

INTRODUCTION TO TEXT EDITORS

A text editor is used to edit plain text files. Text editors differ from word processors, such as

Microsoft Word or WordPerfect, in that they do not add additional formatting information to

Page 3: Text editors project

documents.  You might write a paper in Word, because it contains tools to change fonts, margins,

and layout, but Word by default puts that formatting and layout information directly into the file,

which will confuse the compiler.  If you open a .doc file in a text editor, you will notice that most

of the file is formatting codes.  Text editors, however, do not add formatting codes, which makes

it easier to compile your code.

Text editors have a feature set different from that of a traditional word processing program.  For

example, most won't let you include pictures, or include tables, or double-space your

writing.  The features of text editors vary from implementation to implementation, but there are

several kinds of features that most editors have.  Below are listed some of the most common and

useful features.

Page 4: Text editors project

ACKNOWLEDGEMENT

The satisfaction that accompanies the successful completion of any task would be incomplete

without the mention of people whose ceaseless cooperation made it possible, whose constant

guidance and encouragement crown all efforts with success. I am extremely grateful to my

teacher ‘Mr.Sir’ for being a source of inspiration and for her constant support in the design,

implementation and evaluation of this term paper. I am thankful to him for his constant

constructive criticism and valuable suggestions, which benefited me a lot while developing the

term paper on ‘Text Editors’. Through this column, it would be my utmost pleasure to express

my warm thanks to him for his encouragement, co-operation and consent as without which I

mightn’t be able to accomplish this term paper.

I would also like to express my thanks to almighty god for his grace and mercy.

Above all, I am extremely thankful to my friends who always remained aside me.

Page 5: Text editors project

ALGORITHM:

1. Display options new, open and exit and get choice.2. If choice is 1 , call Create() function.3. If choice is 2, call Display() function.4. If choice is 3, call Append() function.5. If choice is 4, call Delete() function.6. If choice is 5, call Display() function.7. Create() 7.1 Get the file name and open it in write mode.  7.2 Get the text from the user to write it.

8. Display() 8.1 Get the file name from user.

8.2 Check whether the file is present or not.8.2 If present then display the contents of the file.

9. Append()    9.1 Get the file name from user.    9.2 Check whether the file is present or not.    9.3 If present then append the file by getting the text to add with the existing file.

10. Delete()     10.1 Get the file name from user.    10.2 Check whether the file is present or not.     10.3 If present then delete the existing file.

Page 6: Text editors project

WAP A C PROGRAM TO CREATE TEXT EDITOR WHICH CONTAIN THE WORKING OF OPEN, SAVE, NEW, EXIT AND RENAME

1 #include<stdio.h>2 #include<conio.h>3 #include<process.h>4 int i,j,ec,fg,ec2;5 char fn[20],e,c;6 FILE *fp1,*fp2,*fp;7 void Create();8 void Append();9 void Delete();10 void Display();11 void main()12 {13 do {

14 printf("\n\t\t***** TEXT EDITOR *****");15 printf("\n\n\tMENU:\n\t-----\n ");16 printf("\n\t1.CREATE\n\t2.DISPLAY\n\t3.APPEND\n\t4.DELETE\n\t5.EXIT\n");17 printf("\n\tEnter your choice: ");18 scanf("%d",&ec);19 switch(ec)20 {

a) case 1:b) Create();c) break;d) case 2:e) Display();f) break;g) case 3:h) Append();i) break;j) case 4:k) Delete();l) break;m) case 5:n) exit(0);

21 }22 }while(1);23 }24 void Create()25 {26 fp1=fopen("temp.txt","w");

Page 7: Text editors project

27 printf("\n\tEnter the text and press '.' to save\n\n\t");28 while(1)29 {30 c=getchar();31 fputc(c,fp1);32 if(c == '.')33 {

a) fclose(fp1);b) printf("\n\tEnter then new filename: ");c) scanf("%s",fn);d) fp1=fopen("temp.txt","r");e) fp2=fopen(fn,"w");f) while(!feof(fp1))g) {h) c=getc(fp1);i) putc(c,fp2);j) }k) fclose(fp2);l) break;

34 }}35 }36 void Display()37 {38 printf("\n\tEnter the file name: ");39 scanf("%s",fn);40 fp1=fopen(fn,"r");41 if(fp1==NULL)42 {

a) printf("\n\tFile not found!");b) goto end1;

43 }44 while(!feof(fp1))45 {

a) c=getc(fp1);b) printf("%c",c);

46 }47 end1:48 fclose(fp1);49 printf("\n\n\tPress any key to continue...");50 getch();51 }52 void Delete()53 {54 printf("\n\tEnter the file name: ");55 scanf("%s",fn);56 fp1=fopen(fn,"r");

Page 8: Text editors project

57 if(fp1==NULL)58 {

a) printf("\n\tFile not found!");b) goto end2;

59 }60 fclose(fp1);61 if(remove(fn)==0)62 {

a) printf("\n\n\tFile has been deleted successfully!");b) goto end2;

63 }64 else

a) printf("\n\tError!\n");65 end2: printf("\n\n\tPress any key to continue...");66 getch();67 }68 void Append()69 {70 printf("\n\tEnter the file name: ");71 scanf("%s",fn);72 fp1=fopen(fn,"r");73 if(fp1==NULL)74 {

a) printf("\n\tFile not found!");b) goto end3;

75 }76 while(!feof(fp1))77 {

a) c=getc(fp1);b) printf("%c",c);

78 }79 fclose(fp1);80 printf("\n\tType the text and press 'Ctrl+S' to append.\n");81 fp1=fopen(fn,"a");82 while(1)83 {

a) c=getch();b) if(c==19)c) goto end3;d) if(c==13)e) {f) c='\n';g) printf("\n\t");h) fputc(c,fp1);i) }j) else

Page 9: Text editors project

k) {l) printf("%c",c);m) fputc(c,fp1);n) }

84 }85 end3: fclose(fp1);86 getch();87 }

OUTPUT :-

Page 10: Text editors project
Page 11: Text editors project

CONCLUSION

Here, I conclude my lines of my term paper on the topic ‘Text Editors’ with the extreme

satisfaction and contentment. This term paper contains brief definition of Text Editor together

with its features and functions.

Added to this, my term paper contains the basic description to Create, Edit, Save,

Delete and Exit from file through C program. It also includes practical implementation of text

editors through complex c program which is created by our group. Also I have sincerely included

the references from where I have made my term paper. This term paper is the outcome of my

hard and laborious work and contains a complete knowledge on the path independent line

integral.

Here, I end my lines with the hope that my term paper will be equally appreciated and

heartily accepted by all. Also, all my faults and mistakes would be forgiven.

REFERENCES :- www.cprogramming.com/texteditors.html

http://en.wikipedia.org/wiki/Text_editor

http://whatis.techtarget.com/definition/text-editor