Advertisement
Antropex

Szacowka

Sep 10th, 2020
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. int main(int argc, const char * argv[], int count,int last) {
  6. system("color F0");
  7. char line[255];
  8.                     //inicjalizacja tablicy charow o rozmarze 255
  9. FILE *fptr;
  10.                     //inicjalizacja pointera do FILE ktory bedzie przetrzymywal wczytany plik
  11. if ((fptr = fopen("TEST.xml", "r")) == NULL) //próba otwarcia pliku .jesli beda problemy funkcja zwrowi null
  12. {
  13.     printf("Blad podczas otwierania pliku \n"); //wyswietlanie komunikatu
  14.     exit(1);
  15. }
  16. int i=0;
  17.  
  18. while (1) //petla ktora nigdy sie nie skonczy
  19. {
  20.     if(fgets(line, 255, fptr) == NULL) break;// fgets pobiera linie tekstu z fptr o rozmiarze 255 i daje je do tablicy line. Jesli nie bedzie linii to metoda zwroci NULL
  21.  
  22.     for(i=0; line[i]>0 && i<255;i++){
  23.             char temp[2];
  24.             temp[0]= line[i];
  25.             temp[1]= '\0';
  26.  
  27.  
  28.             if(temp[0] == '<') {
  29.                 SetColor(25);
  30.                 printf("%s", temp); //wyswietlamy linie
  31.                 SetColor(4);
  32.                 last = 4;
  33.             }else if(temp[0] == '>') {
  34.                 SetColor(25);
  35.                  printf("%s", temp); //wyswietlamy linie
  36.                   last = 0;
  37.                 SetColor(0);
  38.             }else if(temp[0] == '/') {
  39.                 SetColor(25);
  40.                  printf("%s", temp); //wyswietlamy linie
  41.                 SetColor(last);
  42.             }else if(temp[0] == '"') {
  43.                 if(count == 0){
  44.                     printf("%s", temp); //wyswietlamy linie
  45.                     SetColor(last);
  46.                     count++;
  47.                 }
  48.                 else{
  49.                     SetColor(27);
  50.                     printf("%s", temp); //wyswietlamy linie
  51.                      count = 0;
  52.                 }
  53.             }else{
  54.                  printf("%s", temp); //wyswietlamy linie
  55.             }
  56.     }
  57. }
  58. fclose(fptr); //zamykamy plik
  59. //getc();
  60. return 0;
  61. }
  62.  
  63. void SetColor(int ForgC)
  64.  
  65.  
  66. {
  67.      WORD wColor;
  68.      HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  69.      CONSOLE_SCREEN_BUFFER_INFO csbi;
  70.      if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  71.      {
  72.           wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0X0F);
  73.  
  74. SetConsoleTextAttribute(hStdOut, wColor);
  75.      }
  76.      return;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement