Тема: C. Warning. Не можу знайти помилку.
Видає попередження: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized] в рядку case 2:searsh(f); break;
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct
{
char vb[100];
char mod[100];
char col[100];
char har[100];
float cina;
}phones;
void new_base()
{
FILE *f;
phones t;
int i,n;
f=fopen("Baza.bd","wb");
printf("\nKilkist telephoniv:");
scanf("%d",&n);
for (i=0;i<n;i++)
{
system("cls");
printf("\n%d-j zapys\n",i+1);
printf("Vyrobnyk: ");
scanf("%s",t.vb);
printf("model: ");
scanf("%s",t.mod);
printf("Kolir: ");
scanf("%s",t.col);
printf("harakterystyky: ");
scanf("%s",t.har);
printf("Cina: ");
scanf("%f",&t.cina);
fwrite(&t,sizeof(t),1,f);
}
fclose(f);
}
int write(FILE *f)
{
system("cls");
phones t;
f=fopen("Baza.bd","rb");
fread(&t,sizeof(phones),1,f);
while (!feof(f))
{
printf("\n%s %s/%s/ %4.2f",t.vb,t.mod,t.col,t.cina);
fread(&t,sizeof(phones),1,f);
}
fclose(f);
printf("\n\n\n...");
getch();
return 0;
}
void searsh(FILE *f)
{
system("cls");
phones t;
int nom;
//system("cls");
printf("\nVvedit nomer zapysu: ");
scanf("%d",&nom);
f=fopen("Baza.bd","rb");
nom--;
fseek(f,nom*sizeof(phones),SEEK_SET);
fread(&t,sizeof(phones),1,f);
printf("\n%s %s/%s/ %4.2f",t.vb,t.mod,t.col,t.cina);
fclose(f);
printf("\n\n\n...");
getch();
}
void redag(FILE *f)
{
system("cls");
phones t;
int nom;
printf("\nVvedit nomer zapysu:");
scanf("%d",&nom);
f=fopen("Baza.bd","r+b");
fseek(f,(nom-1)*sizeof(phones),SEEK_SET);
printf("\nVvedennya novoiinformacii:\n");
printf("Vyrobnyk: ");
scanf("%s",t.vb);
printf("model: ");
scanf("%s",t.mod);
printf("Kolir: ");
scanf("%s",t.col);
printf("harakterystyky: ");
scanf("%s",t.har);
printf("Cina: ");
scanf("%f",&t.cina);
fwrite(&t,sizeof(t),1,f);
fclose(f);
printf("\n\n\n");
}
void dodav(FILE *f)
{
system("cls");
phones t;
int i,new;
f=fopen("Baza.bd","ab");
printf("\nVvedit kilkist novyh zapusiv:");
scanf("%d",&new);
while (new<1)
{
printf("\nNevirna kilkist zapysiv...");
printf("\nVvedit kilkist novyh zapysiv: ");
scanf("%d",&new);
}
for (i=0;i<new;i++)
{
printf("Vyrobnyk: ");
scanf("%s",t.vb);
printf("model: ");
scanf("%s",t.mod);
printf("Kolir: ");
scanf("%s",t.col);
printf("harakterystyky: ");
scanf("%s",t.har);
printf("Cina: ");
scanf("%f",&t.cina);
fwrite(&t,sizeof(t),1,f);
}
fclose(f);
printf("\n\n\n...");
}
void delet(FILE *f)
{
system("cls");
phones t[50];
f=fopen("Baza.bd","rb");
int nom,i=-1,j;
printf("\nVvedit nomer zapysu:");
scanf("%d",&nom);
while (!feof(f))
{
i++;
fread(&t[i],sizeof(phones),1,f);
}
fclose(f);
f=fopen("Baza.bd","wb");
for (j=0;j<i;j++)
if (j!=(nom-1)) fwrite(&t[j],sizeof(phones),1,f);
fclose(f);
printf("\n\n\n...");
}
int main()
{
FILE *f;
int pp;
while (pp!=0)
{
system("cls");
printf("\nRobota z bazoyu dannyh....");
printf("\nVyberit potribnu diyu:\n");
printf("\n1 stvorenya novoi bazu danuh");
printf("\n2 poshuk abonenta za indexom");
printf("\n3 redaguv vubranogo zapuzu");
printf("\n4 dodav novuh danuh u bazu");
printf("\n5 vuved infom pro vsih korustuvachiv");
printf("\n6 vudalen vubranoi infomazii");
printf("\n0.....Vyhid z programmy....\n");
scanf("%d",&pp);
switch (pp)
{
case 1: new_base(); break;
case 2: searsh(f); break;
case 3: redag(f); break;
case 4: dodav(f); break;
case 5: write(f); break;
case 6: delet(f); break;
}
}
return 0;
}