Design problem

440 views
376 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
440
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Design problem

  1. 1. DESIGN PROBLEM CSE207TTopic:Design a text editor in linuxSubmitted by:SANJAY KUMAR CHAKRAVARTIROLL:A28SEC:K2R13REG:11006964 Submitted to: Mr. Sandeep Ranjan Cse dept.,LPU Phagwara,Punjab 144402
  2. 2. ABSTRACTText editor is highly essential in every operating system.Without texteditor an operating system look likes ,trees without leaves.To Designa text editor is very tough task.But I have made easy to understand.This Design Problems gives a learning environment ,with theoreticallyand practically.This Design paper contain some features,so why thiswill helpful for all.The features are listed below: 1. Modulization of Design problems 2. Comment line in programme 3. Best approach of Algorithms provided 4. Best working model on file So,these features of text editor in this paper make different to all.
  3. 3. CONTENTSTopic Name Page Number
  4. 4. INTRODUCTION 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 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 wont 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.1.Creating a new file2.Delete an existing file3.Save a file4.counting of charaters,words,ros,coloms and etc.These are basic work of a text editor. An advance text editor contains many features asfollowing:1.coloring2.Font changing3.Draw panel
  5. 5. PREREQUISITEThere are some prerequisite for Design a text editor as given following:1.Knowledge of „c‟ language2.Best knowledge of file handling3.Linux operating
  6. 6. DESIGNED METHHODOLOGYTo Design a text editor a plan should must keep in mind which segmentsare require at which position.First of all create all requied module usingstructures or functions. In this project I have used mostly functions,becaude it will easily understandable.There are two important steps forwriting a progrrame for text editor as following:1.Algorithm2.CodeNow, at first I am discussing about “algorithm” using functions.ALGORITHM:F1.void passwd()step 1. Enter your name in “name” 2. Enter your age in “age” 3. Pass=rand()/10000+age+(int)name 4. Print remember your password 5. Enter your password in “pas” 6. If (pas==pass) Then call show() function Else Print Invalid password try again Goto step 5. 7. Stop.void show()
  7. 7. step1.print “press following key as given menu:1.Menu 2.Search 3.View4.Help” in keyStep2: if (key=1) Then call menu() function Else if (key=2) Then call search() function Else if(key=3) Then call view() function Else if(key=4) Then call help() function Else Print “Sorry wrong choice” Goto step1.Step3: exit.void Create()Step1: call show() functionStep2:open an exist file fp1=fopen(“temp.txt”,”w+”)Step3: print “Type your text and press ESCAPE to save”Step4:while(1) C=getchar();
  8. 8. countc++;fputc(c,fp1);if(c==13),thenrows++;row=rows;else if(c==32),thencountw1++;countw=countw1;else if(c==8),thencountc1--;countc=countc1;else if(c == 27),thenclose file:fclose(fp1)Step5:call count() functionStep6:print “Enter filename ” in fnStep7:open both file temp.txt and fnStep8:while(!feof(fp1))c=getc(fp1) putc(c,fp2)Step9:exit
  9. 9. void Delete()Step1:call function show()Step2:Enter a file to be deleted in fnStep3:Open the file i.e fp=fopen(fn, ”r”) If(fp==NULL),then Print “File not foundStep4:rm=remove(fn) If(rm==0),then Printf “file successfully deleted”Step5:exitvoid Display()Step1:call show() functionStep2:Enter filename to be open in fnStep3:open file i.e fp=fopen(fn,”r”) If(fp==NULL),then Print “file not found” Else While(!feof(fn)) C=getc(fn) Print value of „c‟Step4:exit
  10. 10. void search()Step1:call function show()Step2:Enter string to be search in strStep3:system(grep “$str” temp.txt)Step4:exitvoid menu()Step1:Enter you choice from list:”1.new file 2.open 3.open with editing4.delete 0.exit” in choiceStep2:if(choice=1),then Call function create() Else If(choice==2),then Call function display() Else If(choice==3),then Call function append() Else if(choice==4),then Call function delete() Else Exit(0)Step3:exit
  11. 11. void count()Step1:print number of characters is “countc”Step2:print number of words is “countw”Step3:print numbers of rows is “row”Step4:exit CODE /*This text editor programme only Run and Compile with linux operating system*/ #include<stdio.h> #include<stdlib.h> int i,j,ec,fg,ec2,countc=0,countw=0,row=1,col; char fn[20],e,c; FILE *fp1,*fp2,*fp; void name(); void cwsh1(); void cws(); void show(); void ohelp(); void fhelp(); void soon(); void look(); void Create(); void sanjeev(); void shubham(); void rahul(); void abhay(); void sanjay(); void Append(); void Delete(); void Display(); void menu();
  12. 12. void passwd();void search();void count();void main(){system("clear");passwd();//show();}void sanjeev(){printf("nnt");printf("┬── ─── ─ ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ────── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──┐n");printf("t│ Name: SANJEE KUMAR, age:20 Years is currently study in LOVELYPROFFESSIONAL UNIVERSITY b.tech 2nd │n");printf("t│ year. He is a bestc and c++ programmer. His primary and secondaryeducation in KENDRIYA VDYALYA │n");printf("t│ NO.-1, bokaro steel city.In class 10th he has got 78% ,In class 12th he hasgot 70%. │n");printf("t│ you can contact with him: │n");printf("t│ Mob:7837830703 │n");printf("t│ email: tunsanju@gmail.com│n");printf("t┴── ──── ──── ─── ── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ────── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ───┴n");int je;scanf("%d",&je);switch(je){default:system("clear");show();break;}}void search(){
  13. 13. char str[20];int ser;printf("tt║1.Copy ║n");printf("tt║2.Cut ║n");printf("tt║3.Paste ║n");printf("tt║4.Back ║n");printf("tt╚═══════════════╝");//printf("nnttEnter string to be searched:");//gets(str);scanf("%d",&ser);switch(ser){case 4:system("clear");show();break;}/*switch(ser){case 1:copy();break;case 2:cut();break;case 3:paste();break;default:exit(0);}*/fp1=fopen("temp.txt","w+");system("grep $str temp.txt");}void look(){printf("╔═══════════════╦═══════════════╦═══════════════╦═══════════════╦═══════════════════════╦════════╗n");printf("║1.Menutt║2.Searcht║3.Viewtt║4.Helptt║5.Corporate with ust║6.Exit║n");
  14. 14. printf("╚═══════════════╩═══════════════╩═══════════════╩═══════════════╩═══════════════════════╩════════╝n");}void help(){int he;printf("tttttt");printf("│ 1.Online Help │n");printf("tttttt│ 2.Offline Help │n");printf("tttttt│ 3.Back │n");printf("tttttt└──── ──── ──── ─┴n"); ───scanf("%d",&he);switch(he){case 1:system("clear");look();ohelp();break;case 2:system("clear");look();fhelp();break;default:system("clear");show();break;}}void show(){int key;look();scanf("%d",&key);system("clear");look();switch(key){case 1:menu();
  15. 15. break;case 2:search();break;case 3:view();break;case 4:help();break;case 5:cwsh();break;case 6:exit(0);//break;}}void cwsh1(){printf("ttttttt│ 1.MANUAL │n");printf("ttttttt│ 2.NAME │n");printf("ttttttt│ 3.Back │n");printf("ttttttt└─ ──── ── ──── ─── ─── ──┴n");}void name(){int nam;printf("n");printf("tttttttt");printf("│ 1.Manual│n");printf("tttttttt│ 2.NAME │■│ 1.SANJEEV │n");printf("tttttttt│ 3.Back │ │ 2.SHUBHAM │n");printf("tttttttt└─ ──────── 3.ABHAY ┴│ │n");printf("tttttttt │ 4.RAHUL │n");printf("tttttttt └── ──── ─── ┴n"); ─── ─── ─scanf("%d",&nam);switch(nam){case 1:system("clear");look();sanjeev();break;
  16. 16. case 2:system("clear");look();//shubham();break;case 3:system("clear");look();//abhay();break;case 4:system("clear");look();//rahul();break;default:system("clear");show();break;}}void cwsh(){int cw;cwsh1();scanf("%d",&cw);switch(cw){case 1:system("clear");look();cws();break;case 2:system("clear");look();//cwsh1();name();break;default:system("clear");show();break;}}
  17. 17. void cws(){system("clear");look();printf("nnTHIS PROGRAMME IS CREATED BY:SANJAY KUMAR CHAKRAVARTIn");printf("nttttREG:11006964nnn");printf("nApart from the efforts of me, the success of this project depends largely onthe encouragement and ");printf("guidelines of many others. I take this opportunity to express my gratitude tothe people who have been");printf(" instrumental in the successful completion of this project." );printf("I would like to show my greatest appreciation to Mr. Sandeep ranjan. I can’t saythank you enough for his");printf(" tremendous support and help. I feel motivated and encouraged every time Iattend his Extra classes.");printf(" Without his encouragement and guidance this project would not havematerialized.");printf("The guidance and support received from all the team members includingn1.SANJEEV KUMAR(LPU)n2.SHUBHAM PATEL(LPU)n3.ABHAY ");printf("KUMAR(LPU)n4.RAHUL TEHLANI(LPU)n who contributed and are contributingto this project, was vital for the success of the"); printf("project. I am grateful for their constant support and help.nn");}void ohelp(){int fl;printf("nn");printf("┬── ─── ─ ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ────────── ──── ─── ─── ─── ─── ┐n");printf("│ │n");printf("│Please go on following link: │n");printf("│ 1.www.gnu.com │n");printf("│ 2.www.cpluplusprogramming.com │n");printf("│ 3.www.cprogramming.com │n");printf("│ 4.www.deniweb.com │n");printf("│ 5.www.math-linux.com/IMG/pdf/Linuxbible.com │n");
  18. 18. printf("│ 6.www.ibblio.org/pub/linux/docs/HOWTO-other-formats/pdf/Linux-Init-HOWTO.pdf │n");printf("└─ ──── ── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ───── ──── ─── ─── ─── ─── ┴n");scanf("%d",&fl);switch(fl){default:system("clear");show();break;}}void fhelp(){printf("nn");printf("┬── ─── ─ ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ────── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ┐n");printf("│A text editor is used to edit plain text files. Text editors differ from wordprocessors, such as Microsoft │n");printf("│Word or WordPerfect in that they do not add additional formattinginformation to documents. You might write │n"); printf("│a paper in Word, becauseit contains tools to change fonts, margins, and layout, but Word by default │n");printf("│puts that formatting and layout information directly into the file, which willconfuse the compiler. If │n");printf("│you open a .doc file in a text editor, you will notice that most of the file isformatting codes. Text │n");printf("│editors, however, do not add formatting codes, which makes it easier tocompile your code. │n");printf("│Text editors have a feature set different from that of atraditional wordprocessing program. For example │n");printf("│most wont let you include pictures, or include tables, or double- space yourwriting. The features of │n");printf("│text editors vary from implementation to implementation, but there areseveral kinds of features that most │n");printf("│editors have. Below are listed some of the most common and useful features.│n");printf("└─ ──── ── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ───── ──── ─── ─── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ┴n");
  19. 19. printf("│ 1.Creating a new file │n");printf("│ 2.Delete an existing file │n");printf("│ 3.Save a file │n");printf("│ 4.counting of charaters,words,ros,coloms and etc.│n");printf("└─ ──── ── ─── ─── ──── ──── ─── ─── ─── ─── ──── ──── ─── ─── ───┴n");printf("These are basic work of a text editor. An advance text editor contains manyfeatures as following:n");printf("┬── ─── ─ ─── ─── ──── ──── ─┐n");printf("│ 1.coloring │n");printf("│ 2.Font changing │n");printf("│ 3.Draw panel │n");printf("└─ ──── ── ─── ─── ──── ──── ┴n");}void soon(){int so;printf("nnntt┬─ ──── ─── ──── ─── ─── ─── ─── ──── ──── ─┐n"); ───printf("tt│ │n");printf("tt│ This module is under construction │n");printf("tt│ 0.Return │n");printf("tt└── ─── ──── ─── ── ──── ─── ─── ─── ─── ──── ──┴n");scanf("%d",&so);switch(so){default:system("clear");show();break;}}void view(){//printf("nttttt1.Largenttttt2.Smallnttttt3.Mediumn");printf("tttt║1.Large ║n");printf("tttt║2.Small ║n");printf("tttt║3.Medium ║n");printf("tttt║4.Back ║n");printf("tttt╚═══════════════╝n");int vi;
  20. 20. scanf("%d",&vi);switch(vi){case 1:system("clear");look();soon();break;case 2:system("clear");look();soon();break;case 3:system("clear");look();soon();break;case 4:system("clear");show();break;}}void count(){printf("nTotal:nnt");printf("Characters:%d",countc);printf("ntwords:%d",countw);printf("ntRows:%d",row);col=countc+countw;if(col>=70){col=0;}else{printf("ntColums:%d",col);}}void passwd(){
  21. 21. char name[28];int age;int pass;int pas;int ent;pass1:printf("nnnnEnter your name:");gets(name);printf("nEnter you age:");scanf("%d",&age);pass=rand()/100000+age+((int)name)/10000;printf("nnnYou password is:%d",pass);printf("nPlease remember you password");pass2:printf("nnnnttEnter your password:");scanf("%d",&pas);system("clear");if(pas==pass){show();//menu();}else{system("clear");printf("nnnttWrong passwordn");printf("nPress desire key:n");printf("n1.Re-generate your password:");printf("n2.Re-enter you password");printf("n0.Exitn");scanf("%d",&ent);switch(ent){case 1:goto pass1;break;case 2:goto pass2;
  22. 22. break;case 0:exit(0);}}}void menu(){do{//printf("╔════════════╗n");printf("║1.New File ║n");printf("║2.Open ║n");printf("║3.Edit ║n");printf("║4.Delete ║n");printf("║5.Back ║n");printf("╚══════════════╝n");scanf("%d",&ec);switch(ec){case 1:Create();break;case 2:Display();break;case 3:Append();break;case 4:Delete();break;case 5:system("clear");show();break;}}while(1);
  23. 23. }void Create(){system("clear");show();int countw1=1,rows=1,countc1=0;fp1=fopen("temp.txt","w+");printf("ntEnter the text and press Esc to savennt");while(1){c=getchar();countc++;fputc(c,fp1);if(c==13){rows=rows+1;row=rows;}else if(c==32){countw1++;countw=countw1;}else if(c==8){countc1=countc1-1;countc=countc1;}else if(c == 27){fclose(fp1);count();ff:printf("ntEnter then new filename: ");scanf("%s",fn);if(fn=="."||fn=="?"||fn=="/"||fn=="!"||fn=="@"||fn=="#"||fn=="$"||fn=="%"||fn=="^"||fn=="&"||fn=="*"||fn=="("){
  24. 24. printf("nnnnntttBad File format try againn");goto ff;}else{fp1=fopen("temp.txt","r");fp2=fopen(fn,"w");while(!feof(fp1)){c=getc(fp1);putc(c,fp2);}fclose(fp2);system("clear");show();}}}}void Display(){//show();printf("ntEnter the file name: ");scanf("%s",fn);fp1=fopen(fn,"r");if(fp1==NULL){printf("ntFile not found!");int fn;scanf("%d",&fn);switch(fn){default:system("clear");show();}}system("clear");look();while(!feof(fp1)){
  25. 25. c=getc(fp1);printf("%c",c);}int del;scanf("%d",&del);switch(del){default:system("clear");show();}end1:fclose(fp1);//menu();//system("clear");//printf("n");//show();}void Delete(){system("clear");look();printf("ntEnter the file name: ");scanf("%s",fn);fp1=fopen(fn,"r");if(fp1==NULL){system("clear");look();printf("ntFile not found!n");int ff;scanf("%d",&ff);switch(ff){default:system("clear");show();}}
  26. 26. fclose(fp1);if(remove(fn)==0){printf("nntFile has been deleted successfully!");int de;scanf("%d",&de);switch(de){default:system("clear");show();break;}}elsesystem("clear");look();printf("ntError!n");show();}void Append(){system("clear");look();printf("ntEnter the file name: ");scanf("%s",fn);fp1=fopen(fn,"r");if(fp1==NULL){system("clear");look();printf("ntFile not found!");int nu;scanf("%d",&nu);switch(nu){default:system("clear");show();
  27. 27. }goto end3;}while(!feof(fp1)){c=getc(fp1);printf("%c",c);}fclose(fp1);printf("ntType the text and press ESCAPE to append.n");fp1=fopen(fn,"a");while(1){c=getchar();//if(c==19)//goto end3;if(c==13){c=n;printf("nt");fputc(c,fp1);}else if(c==27){system("clear");show();}else{printf("%c",c);fputc(c,fp1);}}end3: fclose(fp1);system("clear"); menu();}
  28. 28. SAMPLE INPUTSThis programme will take some inputs for working with a file.Some inputs:Name:sanjay kumar chakravartiAge:20Selection of menu:

×