Small text editor (use can be wildcard * and?)

xiaoxiao2021-03-05  28

Small text editor (using can be used to ensure that the file you want to process is in the current working directory. #include #include #include #include

Typedef struct {char Word [20]; int future;} WordType; WordType Seekword; / * seekword Used to find the word * / WordType Save; / * save uses the word read from the file * /

INT CHER CH / * Checks if it is a legal character * / {if (CH <= '9' && ch> = '0' || CH <= 'Z' && ch> = 'a' || CH <= 'Z' && ch> = 'a') Return 1; Else Return 0;

}

Void length () / * Calculate the length of Word [] in Seekword and Save * / {INT i;

Seekword.Length = 0; save.Length = 0; for (i = 0; seekword.word [i]! = '/ 0'; i ); seekword.length = i; for (i = 0; save.word [ I]! = '/ 0'; i ); save.length = i;}

INT compare () / * Compare Word [] in Save and Seekword matching, if matching, return 0 * / {int LENGTH1, LENGTH2, I, J, FLAG1, FLAG2, BREAKPOINT; CHAR Segment1 [20], Segment2 [20], CH;

IF (seekword.length <= save.Length) {for (i = 0; i <20; i ) {if (seekword.word [i] == '?' || seekword.word [i] == '* ') {Ch = seekword.word [i]; Breakpoint = i;}}} = f (cH =='? '|| CH ==' * ') {for (i = 0; i

Else Return 0;

} void seek (char filename [10]) / * Find the location of seekword in the file and output * / {file * fp; char ch; INT i, J, K, NUM; TYPEDEF Struct Word_Place {Char Word [20]; Int row; int line; struct word_place * next;} seekplace; seekplace * header, * link; fp = fopen (filename, "r"); if (fp == null) {printf ("THE FILE CAN NOT BE OPENED! / NMAYBE THE IS NOT IN CURRENT WORKING DIRECTORY / N"); EXIT (0);} IF ((link = (seekplace)) Malloc (SIZEOF (SIZEKPLACE))) == NULL ) {Printf ("there is no free space in momory!"); Exit (0);} header = link; num = 0; if (Feof (fip)) {Printf ("The File IS Empty!"); Exit (0);} j = 0; K = 1; while (! Feof (fp)) {i = 0; while (CHECK (CH = FGETC (FP))) {J ; Save.Word [i ] = CH; IF (i> 19) {Printf ("Sorry, THE WORD IS TOON / N"); EXIT (0);}} J ; for (; i <= 19; i ) save.word [i] = '/ 0 '; length (); if (Compare ()! = 0) {Num ; if ((link-> next = (seekplace *) Malloc (SIZEOF (SeekPlace))) == NULL) {Printf ("there is no free paractin"; exit (0) Link = link-> next; strcpy (link-> word, save.word); link-> row = k; link-> line = j-save.length; link-> next = null;} if (ch == '/ n') {k ; j = 0;} }printf ("

/ NTHE WORD APPEARS% D Times in the file./n/n" ,num); if (Num! = 0) {Printf ("The Place WHERE IT APPEARS IS (ROW, LINE): / N"); for ( Link = header-> next; link! = null; link = link-> next) {printf ("% s / t (% D,% d) / n", link-> word, link-> row, link- > line);}}}}}}}}}}; if (fclose (fp)) {Printf ("The File Cannot Be Closed!"); exit (0);}}

MAIN () {INT I; Char FileName [10]; char CH; do {DO {clrs (); printf ("************************ *********************************************************** *** / n "); Printf (" * * / n "); Printf (" * copyright belongs to mb459@sohu.com version 1.0 * / n "); Printf (" * 117cn.x168.net/bbs * / N "); Printf (" ****************************************** ********************************** / N "); Printf (" / Ninput The Word you want to seek : "); Scanf ("% s ", seekword.word); Printf (" / n "); Printf (" Which file do you want to find the word in? / N (make Sure the file is in the current work) Directory) / NPLEASE INPUT The File Name: "); Scanf ("% s ", filename); seek (filename); Printf (" / n / n "); Printf (" Press' ESC 'to EXIT, PRESS' RETURN 'to transferue./N "); ch = getCH ();} while (ch == 13); if (ch == 27) exit (0); if (ch! = 27 && ch! = 13) P RINTF ("Sorry! Please tell me what do you want to do next./n");} while (ch = getch () == 13);}

转载请注明原文地址:https://www.9cbs.com/read-33348.html

New Post(0)