It is supposed to tell me the occurrences of letters both upper and lower case and digit and non letter nor digits characters ,,but it does nothing ,,please help as soon as possible

#include<stdio.h>
#include<ctype.h>
#include<conio.h>

int main(){
    FILE *fp,*f2,*f3;
    char ch,temp;
    int i,j;
    int lowercase[26]={0};
    int upperCase[26]={0};
    int    digits[10]={0};
    int nonLetterNordigit=0;
    if((fp=fopen("myFile.txt","r+"))==NULL)
            perror("openning file!");

        f2=fp;
        f3=fp;    
          //read char

          //replace \n with '\0'    
       while((temp=fgetc(fp))!='\n'){
            int ocurr=0;
            //start from begining of file 
               f2=f3;
              while((ch=fgetc(f2))!='\n'){
                         if(ch==temp)             
                               ++ocurr;
                          }
                  printf("%d\t",ocurr);       

                 if(isalnum(temp) !=0){

                                if((isdigit(temp))!=0){
                                    switch(temp){
                                                  case '0':
                                                   digits[0]=ocurr; 
                                                       break;        
                                                  case '1':
                                                       digits[1]=ocurr;
                                                       break;
                                                  case '2':
                                                       digits[2]=ocurr;
                                                       break;
                                                  case '3':
                                                       digits[3]=ocurr;
                                                       break;
                                                  case '4':
                                                       digits[4]=ocurr;
                                                       break;
                                                  case '5':
                                                       digits[5]=ocurr;
                                                       break;
                                                  case '6': 
                                                       digits[6]=ocurr;
                                                       break;
                                                  case '7':
                                                       digits[7]=ocurr;
                                                       break;
                                                  case '8':
                                                       digits[8]=ocurr;
                                                         break;
                                                  case '9':        
                                                       digits[9]=ocurr;
                                                         break;  
                                                   default :
                                                     break;                         
                                                 }

                                       } else if((islower(temp))!=0){ 
                                         switch(temp){
                                                case 'a':
                                                   lowercase[0]=ocurr; 
                                                       break;        
                                                  case 'b':
                                                       lowercase[1]=ocurr;
                                                       break;
                                                  case 'c':
                                                       lowercase[2]=ocurr;
                                                       break;
                                                  case 'd':
                                                       lowercase[3]=ocurr;
                                                       break;
                                                  case 'e':
                                                       lowercase[4]=ocurr;
                                                       break;
                                                  case 'f':
                                                       lowercase[5]=ocurr;
                                                       break;
                                                  case 'g': 
                                                       lowercase[6]=ocurr;
                                                       break;
                                                  case 'h':
                                                       lowercase[7]=ocurr;
                                                       break;
                                                  case 'i':
                                                       lowercase[8]=ocurr;
                                                       break;
                                                  case 'j':        
                                                       lowercase[9]=ocurr;
                                                       break;  
                                                  case 'k':
                                                   lowercase[10]=ocurr; 
                                                       break;        
                                                  case 'l':
                                                       lowercase[11]=ocurr;
                                                       break;
                                                  case 'm':
                                                       lowercase[12]=ocurr;
                                                       break;
                                                  case 'n':
                                                       lowercase[13]=ocurr;
                                                       break;
                                                  case 'o':
                                                       lowercase[14]=ocurr;
                                                       break;
                                                  case 'p':
                                                       lowercase[15]=ocurr;
                                                       break;
                                                  case 'q': 
                                                       lowercase[16]=ocurr;
                                                       break;
                                                  case 'r':
                                                       lowercase[17]=ocurr;
                                                       break;
                                                  case 's':
                                                       lowercase[18]=ocurr;
                                                       break;
                                                  case 't':        
                                                       lowercase[19]=ocurr;
                                                       break;
                                                 case 'u':
                                                   lowercase[20]=ocurr; 
                                                       break;        
                                                  case 'v':
                                                       lowercase[21]=ocurr;
                                                       break;
                                                  case 'w':
                                                       lowercase[22]=ocurr;
                                                       break;
                                                  case 'x':
                                                       lowercase[23]=ocurr;
                                                       break;
                                                  case 'y':
                                                       lowercase[24]=ocurr;
                                                       break;
                                                  case 'z':
                                                       lowercase[25]=ocurr;
                                                       break;
                                                  default:
                                                          break; 
                                                  }                           

                                      }else if((isupper(temp))!=0){           
                                            switch(temp){
                                                case 'A':
                                                   upperCase[0]=ocurr; 
                                                       break;        
                                                  case 'B':
                                                       upperCase[1]=ocurr;
                                                       break;
                                                  case 'C':
                                                       upperCase[2]=ocurr;
                                                       break;
                                                  case 'D':
                                                       upperCase[3]=ocurr;
                                                       break;
                                                  case 'E':
                                                       upperCase[4]=ocurr;
                                                       break;
                                                  case 'F':
                                                       upperCase[5]=ocurr;
                                                       break;
                                                  case 'G': 
                                                       upperCase[6]=ocurr;
                                                       break;
                                                  case 'H':
                                                       upperCase[7]=ocurr;
                                                       break;
                                                  case 'I':
                                                       upperCase[8]=ocurr;
                                                       break;
                                                  case 'J':        
                                                       upperCase[9]=ocurr;
                                                       break;  
                                                case 'K':
                                                   upperCase[10]=ocurr; 
                                                       break;        
                                                  case 'L':
                                                       upperCase[11]=ocurr;
                                                       break;
                                                  case 'M':
                                                       upperCase[12]=ocurr;
                                                       break;
                                                  case 'N':
                                                       upperCase[13]=ocurr;
                                                       break;
                                                  case 'O':
                                                       upperCase[14]=ocurr;
                                                       break;
                                                  case 'P':
                                                       upperCase[15]=ocurr;
                                                       break;
                                                  case 'Q': 
                                                       upperCase[16]=ocurr;
                                                       break;
                                                  case 'R':
                                                       upperCase[17]=ocurr;
                                                       break;
                                                  case 'S':
                                                       upperCase[18]=ocurr;
                                                       break;
                                                  case 'T':        
                                                       upperCase[19]=ocurr;
                                                       break;
                                                    case 'u':
                                                   upperCase[20]=ocurr; 
                                                       break;        
                                                  case 'V':
                                                       upperCase[21]=ocurr;
                                                       break;
                                                  case 'W':
                                                       upperCase[22]=ocurr;
                                                       break;
                                                  case 'X':
                                                       upperCase[23]=ocurr;
                                                       break;
                                                  case 'Y':
                                                       upperCase[24]=ocurr;
                                                       break;
                                                  case 'Z':
                                                       upperCase[25]=ocurr;
                                                       break;
                                                  default:      
                                                      break;
                                                 }   
                                         }                   

                                }else 
                                 nonLetterNordigit=ocurr;
          }  

 //print 
      fprintf(fp,"\n\n%s\n","a   b  c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t   u   v   w   x   y   z ");
       for(i=0;i<26;i++)
          fprintf(fp,"%d ",lowercase[i]);

      fprintf(fp,"\n");
     fprintf(fp,"%s\n","A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z");      
       for(i=0;i<26;i++)
          fprintf(fp,"%d  ",upperCase[i]); 
         fprintf(fp,"\n");    
          fprintf(fp,"%s\n","0  1  2  3  4  5  6  7  8  9 ");          
          for(i=0;i<9;i++)
           fprintf(fp,"%d  ",digits[i]);  

        fclose(fp);
        fclose(f2);
        fclose(f3);        
            getch();    
     return 0;       
    }

OMG!!
what actually you are trying to do???

I don't know what you are doing in your code, cause I just know it gets stuck in the first "while" loop as I can see, but I have a suggestion for you.

My idea is, make an integer array which its size is the number of ascii characters you want to record the number of occurrence for, say from "!" to "z"(should be about 90 chars, please check the ascii table), and remember to initialize your array to ZERO, and then open your file and read one char at a time, once you read the char, convert it to ascii code(please don't panic, it's very easy to convert a char to relevant decimal ascii code in C, look for static_cast<>()) and increase the array value for that ascii value by ONE. Once you are done, you have an array that if you, for example, print out its 65th element, you have number of occurrence of "A".

Hope that helped; although if you are still not clear, let me know, I'll try to explain further.

U want to count number of Capital small alphabets and numbers??
If so here is piece of code may help u ..

Assuming Capha, Salpha and num arrays decaired and initialized and fs is source FILE..

while( (ch=getch(fs) != EOF)
{
       if(isupper(ch))
              Capha[ch -'A'] += 1;
       else if(islower(ch))
              Sapha[ch -'a'] += 1;
       else if(isdigit(ch))
              num[ch -'0'] += 1;
}

isupper() , islower and isdigit() functions are in ctype.h you have to include it google about function if want more info ..
Here you will scan a char from file and check whether it is a UpperCase LowerCase or
numeric .. thn using arrays we keeping track of number of counts..
Hope its clear

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.