Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int k; // tyle razy keyword
- int p; // licznik nawiasow
- int f; // flaga do wykrywania nawiasow
- int i, j, h; // iterator dla petli
- int match; // flaga 1 gdy sie zgadza slowo
- int wordlength; // dlugosc slowa, licz od 1
- int tmp;
- int smiec;
- char c; // bierzacy char
- char prev; // poprzedni znak wczytany
- char last; // ostatni zapisany znak
- char next; // nastepny znaczek
- char word[10];
- char pword[10];
- int main (int narg, char *arg[])
- {
- FILE* in = fopen (arg[1], "rt");
- FILE* out = fopen (arg[2], "wt");
- strcpy (word, arg[3]); // wkleja do word keyword
- wordlength=strlen(word);
- last=' ';
- for (i = 0; word[i] != '\0'; i++) { // podmienia slowo kluczowe
- if(isdigit(word[i]))
- {
- if(word[i]=='0') pword[i] = '9';
- else pword[i]=word[i]-1;
- } else
- {
- pword[i]=tolower(word[i]);
- }
- }
- pword[i]='\n';
- do {
- f = 1;
- c = fgetc(in);
- if (c == '*') { // jesli komentarz sie konczy
- tmp = fgetc(in);
- if(tmp == '/'){
- p--;
- c = ' ';
- f = 0;
- } else ungetc(tmp, in);
- }
- if (c == '/') { // jesli komentarz sie zaczyna
- tmp = fgetc(in);
- if(tmp == '*'){
- c = tmp;
- p++;
- f = 0;
- } else ungetc(tmp, in);
- }
- if ((p == 0)&&(f == 1)) // ten kod wykona sie poza komentarzem
- {
- if (isblank(last) && c==word[0]){
- //printf("tutaj");
- j=0;
- while(1)
- {
- if (c!=word[j]) break;
- c = fgetc(in);
- j++;
- if (c == EOF) break;
- //printf("%d", j);
- }
- if (j==wordlength){
- //fscanf(in, "%c", &tmp);
- //next = tmp;
- //ungetc(tmp, in);
- if ((!(isalnum(c)))||c==EOF){
- match = 1;
- k++;
- }
- } else match = 0;
- if (match){
- for (i=0;i<j;i++) {
- putc(word[i], out);
- }
- } else {
- for (i=0;i<j;i++) {
- putc(pword[i], out);
- }
- }
- }
- if (isdigit(c)){if(c=='0') c='9'; else c--;}
- if (isupper(c)){c=tolower(c);}
- if (c!=EOF) {putc(c, out);}
- last = c;
- if(ispunct(c)) last = ' '; //??
- //printf("%d ",c);
- }
- prev = c;
- } while (c!=EOF);
- printf ("%d",k);
- fclose (in);
- fclose (out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement