Warning:'loop' has not been used!

This is a discussion on Warning:'loop' has not been used! within the C Programming forums, part of the General Programming Boards category; Hi I keep getting the following warnings:'loop' has not been used-line 34 & 153. I cannot delete data and it ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    6

    Warning:'loop' has not been used!

    Hi
    I keep getting the following warnings:'loop' has not been used-line 34 & 153. I cannot delete data and it will not let me view data properly. Can someone see where I have gone wrong plz!

    I am using Salford compiler, Plato 2 on windows.


    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    int load();
    void add();
    void displayall();
    void findone(int);
    void update(int);
    void deletee(int);
    void sort();
    void display(int);
    void update(int which);
    void delete1(int which);
    
    
     FILE*fin,*fout;
     struct card
                {
                char name[30];
                float salary;
                int holidays;
                }employee[10];     /*or as many as you want*/
                
     struct card temp;
     int count=0;
     int size;
     int choice=0;
     char dummy[30];
     
     
    int main(void)
     {
            int loop;
            
             size=sizeof(struct card);      /*gives size in bytes*/
             
             do
             {
                    printf("\n\nFile Manager\n\n");
                    printf("Load File from Disk....1\n");
                    printf("Add a Record...........2\n");
                    printf("Display All Records....3\n");
                    printf("Find One Record........4\n");
                    printf("Update Record..........5\n");
                    printf("Delete Record..........6\n");
                    printf("Sort by Name...........7\n");
                    printf("Save and Exit..........8\n");
                    
                    do
                    {
                            printf("\nEnter Choice:");
                            fgets(dummy,30,stdin);
                            choice=atoi(dummy);
                    }
                    while(choice<1&&choice>8); 
                    
                    switch(choice)
                    {
                            case 1: count=load();   break;
                            case 2: add();          break;
                            case 3: displayall();   break;
                            case 4: findone(1);             /*these all start with find*/
                                    break;                  /*1 for display option*/
                            case 5: findone(2);             /*2 for update option*/
                                    break;                                  
                            case 6: findone(3);             /*3 for delete option*/
                                    break;
                            case 7: sort();         break;
                            case 8: ;
                     }
                     
             }
                    while(choice!=8);
                    fout=fopen("test.dat","wb");     /*note write mode*/
                    fwrite(employee,size,count,fout);
                    fclose(fout);
                    
             return 0;
    }
    
    void add()
    {
            do
            {
                    printf("Name:");
                    fgets(temp.name,30,stdin);      /*scanf no good for multiple names*/
                    printf("Salary:");
                    fgets(dummy,30,stdin);          /*fgets throughout for consistency*/
                    temp.salary=atof(dummy);
                    printf("Holiday Entitlement:");
                    fgets(dummy,30,stdin);
                    temp.holidays=atoi(dummy);
                    employee[count]=temp;
                    count++;
                    printf("More(y/n)");
                    fgets(dummy,30,stdin);
             }
             while(strcmp(dummy,"n\n")!=0);         /*fgets keeps the \n*/
    }
    
    int load()
    {
            int loop=0;
            fin=fopen("test.dat","rb");              /*read mode*/
            while(fread(&employee[loop],size,1,fin)!=EOF)
                    loop++;                         /* take count*/
            fclose(fin);
            return loop;                            /*return count to main()*/
    }
    
    void displayall()
    {
            int loop;
            
            for(loop=0;loop<count;loop++)
                    display(loop);
    }
    
    void findone(int option)
    {
            int loop=0;
            int found=0;
            
            printf("\nEnter employee name:");
            fgets(dummy,30,stdin);
            for(loop=0;loop<count&&found==0;loop++){
                    if(strcmp(dummy,employee[loop].name)==0)
                            found=1;
            if(found==0)
                    printf("No one here called %s\n",dummy);
            else
            {
                    loop--;                 /*undo last loop++*/
                    if(option==1)
                            display(loop);
                    else if(option==2)
                            update(loop);
                         else
                            delete1(loop);
           }     
    }}
    
    void display(int which)
    {
            printf("%s\t",employee[which].name);
            printf("%.2f\t",employee[which].salary);
            printf("%d\n",employee[which].holidays);
    }
    
    void update(int which)
    {   
            int loop;
            
            printf("Name:%s New Name or [Return]:",employee[which].name);
            fgets(temp.name,30,stdin);
            if(strlen(temp.name)>1)
                    strcpy(employee[which].name,temp.name);
            printf("Salary%.2f New Value or 0:",employee[which].salary);
            fgets(dummy,30,stdin);
            temp.salary=atof(dummy);
            if(temp.salary>0)
                    employee[which].salary=temp.salary;
            printf("Holidays%d New Value or 0:",employee[which].holidays);
            fgets(dummy,30,stdin);
            temp.holidays=atoi(dummy);
            if(temp.holidays>0)
                    employee[which].holidays=temp.holidays;
    }
    
    void delete1(int which)
    {
            int loop;
            
            count--;
            for(loop=which;loop<=count;loop++)              /*overwrite with*/
                    employee[loop]=employee[loop+1];        /*the one below*/
    }
    
    void sort(void)
    {
            int loop;
            int done=1;                                     /*finished sorting? flag*/
            
            while(done==1)
            {
                    done=0;                                  /*assumed sorted*/
                    for(loop=0;loop<count-1;loop++)
                            if(strcmp(employee[loop].name,employee[loop+1].name)>0)
                            {
                                    temp=employee[loop];
                                    employee[loop]=employee[loop+1];
                                    employee[loop+1]=temp;
                                    done=1;                 /*no it is't*/
                                    
                            }   
            }
    }

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    " warnings:'loop' has not been used-line 34 & 153."

    This is because you dont use the variable loop in those functions.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i'm not going over the logic in your code.....but, as for the warning, you declared "loop" in main but you never use it anywhere
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    2
    Code:
    *snip*
    
     int count=0;
     int size;
     int choice=0;
     char dummy[30];
     
    *snip*
                    do
                    {
                            printf("\nEnter Choice:");
                            fgets(dummy,30,stdin);
                            choice=atoi(dummy);
                    }
                    while(choice<1&&choice>8);

    Just some things I noticed:

    - you don't need global variables here
    - the above loop is broken
    - what happens if the load file doesn't exist?

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well, considering the fact that they aren't passing any variables to any functions, I'd say they do in fact need globals.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    2
    Obviously I implied that local variables should be passed instead

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21