problem with function that count the symbols in identificators in *.c files

I need to count the symbols in identificators in .c files and I make that piece of code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
FILE *fin;
      char row[256], path[50];
      int count=0,i;
      
      printf("\nEnter the path and the name of the C program that you wish to open"
            "\npath+name: ");

      fin=fopen(gets(path),"rt");

      if (fin==NULL){
            printf("\nCan't open the file!\n");
            return 0;
      }

      int quotes[30],c=-1,z=-1,rquotes[30],ap=0,y=0,t=0;
      
      do{
            if(fgets(row,256,fin)!=NULL){
                  
                  for(i=0;row[i];++i){
                        if(row[i]=='"'){
                              c+=1;
                              quotes[c]=i;
                        }
                  }

                  if(c>0){

                  for(i=0;i<=c;++i){
                        z+=1;
                        if(row[quotes[i]-1]!='\\')
                              rquotes[z]=quotes[i];
                  }

                  for(i=0;i<rquotes[0];){
                        if(row[i]=='\''){
                                          if(row[i+1]='\'')
                                                i+=2;
                                          else{
                                                      if(row[i+1]=='\\')
                                                                  i+=4;
                                                      else
                                                            i+=3;
                                          }
                              }
                              
                        else{
                        if(row[i]!='='&&';'&&'+'&&'-'&&'('&&')'&&'#'&&'<'&&'>'&&','&&'{'&&'}'&&'['&&']'
                              &&'&'&&'|'&&'!'&&'*'&&'/'&&'?'&&'%'&&' ')
                              count++;
                        ++i;
                        }
                  }
            
                  for(t=1;t<=c;t+=2){
                        for(i=++rquotes[t];i<rquotes[t+1];){
                              if(row[i]=='\''){
                                          if(row[i+1]='\'')
                                                i+=2;
                                          else{
                                                      if(row[i+1]=='\\')
                                                                  i+=4;
                                                      else
                                                            i+=3;
                                          }
                              }
                              
                        else{
                        if(row[i]!='='&&';'&&'+'&&'-'&&'('&&')'&&'#'&&'<'&&'>'&&','&&'{'&&'}'&&'['&&']'
                              &&'&'&&'|'&&'!'&&'*'&&'/'&&'?'&&'%'&&' ')
                              count++;
                        ++i;
                        }


                        }
                  }

            }/* za noviq if*/      
                  else{
                  
                        for(i=0;i<strlen(row);){
                        if(row[i]=='\''){
                                          if(row[i+1]='\'')
                                                i+=2;
                                          else{
                                                      if(row[i+1]=='\\')
                                                                  i+=4;
                                                      else
                                                            i+=3;
                                          }
                              }
                              
                        else{
                        if(row[i]!='='&&';'&&'+'&&'-'&&'('&&')'&&'#'&&'<'&&'>'&&','&&'{'&&'}'&&'['&&']'
                              &&'&'&&'|'&&'!'&&'*'&&'/'&&'?'&&'%'&&' ')
                              count++;
                        ++i;
                        }
                  }

                  } //za elsa na noviq if
            
                  
            }

      }while(feof(fin)==NULL);

      fclose(fin);
      printf("\n symbols - %d\n",count);
      return 0;

The big problem is that the code is now very complex and it can't count correctly and I need to add some other cases (not to count in comments for example).
P.S Sorry for awful English.
All these type lines are wrong

if(row[i]!='='&&';'&&'+'&&'-'&&'('&&')'&&'#'&&'<'&&'>'&&','&&'{'&&'}'&&'['&&']'
&&'&'&&'|'&&'!'&&'*'&&'/'&&'?'&&'%'&&' ')

if( row[i] != '=' && row[i] != ';' ... ) is correct.

Or use string::find.

1
2
if( string( "=;+-()#<>,{}[]&|!*/?% " ).find( row[i ] ) != string::npos )
   cout << "found it." << endl;

Topic archived. No new replies allowed.