Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- int main(int argc, const char * argv[], int count,int last) {
- system("color F0");
- char line[255];
- //inicjalizacja tablicy charow o rozmarze 255
- FILE *fptr;
- //inicjalizacja pointera do FILE ktory bedzie przetrzymywal wczytany plik
- if ((fptr = fopen("TEST.xml", "r")) == NULL) //próba otwarcia pliku .jesli beda problemy funkcja zwrowi null
- {
- printf("Blad podczas otwierania pliku \n"); //wyswietlanie komunikatu
- exit(1);
- }
- int i=0;
- while (1) //petla ktora nigdy sie nie skonczy
- {
- 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
- for(i=0; line[i]>0 && i<255;i++){
- char temp[2];
- temp[0]= line[i];
- temp[1]= '\0';
- if(temp[0] == '<') {
- SetColor(25);
- printf("%s", temp); //wyswietlamy linie
- SetColor(4);
- last = 4;
- }else if(temp[0] == '>') {
- SetColor(25);
- printf("%s", temp); //wyswietlamy linie
- last = 0;
- SetColor(0);
- }else if(temp[0] == '/') {
- SetColor(25);
- printf("%s", temp); //wyswietlamy linie
- SetColor(last);
- }else if(temp[0] == '"') {
- if(count == 0){
- printf("%s", temp); //wyswietlamy linie
- SetColor(last);
- count++;
- }
- else{
- SetColor(27);
- printf("%s", temp); //wyswietlamy linie
- count = 0;
- }
- }else{
- printf("%s", temp); //wyswietlamy linie
- }
- }
- }
- fclose(fptr); //zamykamy plik
- //getc();
- return 0;
- }
- void SetColor(int ForgC)
- {
- WORD wColor;
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0X0F);
- SetConsoleTextAttribute(hStdOut, wColor);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement