c - When we search word in txt file how we could colour in txt file -


hi make code @ c find string in txt file code has result how many times found string , pos first character want colour string in txt file when find string had no idea how can code:

#include<stdio.h> #include<stdlib.h> #include<string.h>  main() {     file*fp;     char fname[100];     char data[20];     char choice;     char key[10];     char*ptr;     int counter=0;     int pos_start;     printf("program start-up....\n");     printf("enter file name: ");     gets(fname);     fp=fopen(fname,"r");     if (fp==null)     {         printf("error:file can not opened\n");         printf("program closed...\n");         exit(1);     }     printf("file opened successfully\n");     printf("do want search string(y/n)");     scanf(" %c",&choice);     while ((choice!='y') && (choice!='n'))     {         printf("do want search string(y/n)");         scanf(" %c",&choice);     }     if (choice=='n')     {         printf("search cancelled\n");         printf("program closed...\n");         exit(1);     }     if (choice=='y')     {         printf("search start-up...\n");         printf("please insert word: ");         scanf("%s",key);         while(!feof(fp))         {             fgets(data,sizeof(data),fp);             ptr = strstr(data,key);             while(ptr!=null)             {                 counter++;                 pos_start=(ptr-data);                 printf("position: %d\n",pos_start);                 ptr= strstr(ptr+1,key);             }         }     }     if (counter==0)         printf("word not found\n");     if(counter>0)         printf("word: %s found: %d times\n",key,counter);     printf("search end\n");     printf("progarm closed...\n");     fclose(fp);     return 0; } 

you cant, text file text file, contains characters , has no formatting (colors, fonts, etc...) whatsoever

you might want @ other text file formats output, example: html.

edit :

if want output result console instead of file, terminals supports ansi colors code. since off-topic (you asked writing file), can refer this question printing colors on terminal.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -