There is a code that searches for the keywords b and displays how many times he met them (in this case (for, while, etc.). How can you make him look for "for (), while ()" ps no matter how far stand brackets => "for (///////// - spaces)"
#include <stdio.h> #include <string.h> int Search(char line[], char word[]) { char *p; int count = 0; //start = line; while(1){ p = strstr(line, word); if(p == NULL)break; ++count; line = p + strlen(word); } return count; } int main(){ int nf = 0, nw = 0, nd = 0, ni = 0; char s[100]; FILE *fp; fp = fopen("f1.txt", "r"); while(fgets(s, 100, fp)){ nf += Search(s, "for"); nw += Search(s, "while"); nd += Search(s, "do"); ni += Search(s, "if"); } fclose(fp); printf("V file f1 vstretilos:\n"); printf("for %d raza \nwhile %d raza \ndo %d raza \nif %d raza\n", nf, nw, nd, ni); return 0; }
(and then all the characters before)in the loop stupidly. - pavelbool findO = false; for ( ;*p || !findO ; p++) findO = *p == '('; if (!findO) return 0; findO = false; for ( ;*p || !findO ; p++) findO = *p == ')'; if (!findO) return 0; return 1;I think the idea further decorate. - pavel