#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct oseba
{
char ime[20];
char priimek[15];
char ulica[50];
char mesto[50];
char tel_st[10];
short ucni_uspeh;
}pod[50];
void vnos(struct oseba pod[],FILE *fd)
{int i;
fd=fopen("DIJAKI.BIN","a+");
for(i=0;i<1;i++)
printf("Vnesi ime: "); scanf("%s",pod[i].ime);
fflush(stdin);
printf("Vnesi priimek: "); scanf("%s",pod[i].priimek);
fflush(stdin);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod[i].ucni_uspeh);
fflush(stdin);
printf("Vnesi ulico in st: ");scanf("%[^\n]s",pod[i].ulica);
fflush(stdin);
printf("Vnesi ime mesta: "); scanf("%s",pod[i].mesto);
fflush(stdin);
printf("Vnesi tel st: "); scanf("%[0-9,-]s",pod[i].tel_st);
fflush(stdin);
fwrite(&pod,sizeof(pod),1,fd);
fclose(fd);
}
void izpis(struct oseba pod[],FILE *fd)
{
fd=fopen("DIJAKI.BIN","r");
fread(&pod,sizeof(pod),1,fd);
fclose(fd);
printf("%s %s\n", pod[0].ime, pod[0].priimek);
printf("Ucni uspeh: %d\n",pod[0].ucni_uspeh);
printf("Ulica: %s\n",pod[0].ulica);
printf("Mesto: %s\n",pod[0].mesto);
printf("Telefonska stevilka: %s\n",pod[0].tel_st);
}
void iskanje(struct oseba pod[],FILE *fd)//pri temule delu potrebujem pomoc matic.
//kako naj pri izbiri ena naredim da najde pac string pa potem
//ga obdelamo oz. izbrisemo
{int a;char iskano[20];
fd=fopen("DIJAKI.BIN","r");
printf("Ali zelis iskati po priimku ali po imenu:\n\n1.) Po imenu\n\n2.) Po priimku\n\n3.) izhod v meni\n\n");
scanf("%d",&a);
system("cls");
int i=0;
if(a==1)
{
printf("\n\nvnesi ime:\n");
scanf("%s",iskano);
while(!feof(fd))
{ //fread(&r,sizeof(struct rec),1,f);
fread(&pod,sizeof(pod),1,fd);
if(strcmp (pod[i].ime,iskano) == 0);// namesto tega probaj dat primerjavo stringov ne strcm,p al pa kej a=b neki probi-***************
{
printf("ime je najdeno.");
system("pause");/*predelaj oz. odstrani ime*//* uredi()*/
i++;
}
}
}
if(a==2)
{
printf("\n\nvnesi priimek:\n");
while(!feof(fd))
{ //fread(&r,sizeof(struct rec),1,f);
/*fread(&pod,sizeof(pod),1,fd);
printf("%s %s\n", pod.ime, pod.priimek);
printf("Ucni uspeh: %d\n",pod.ucni_uspeh);
printf("Ulica: %s\n",pod.ulica);
printf("Mesto: %s\n",pod.mesto);
printf("Telefonska stevilka: %s\n\n\n",pod.tel_st);*/
}
}
if(a==3)
{exit(1);}
else {system("cls");printf("Napacn vnos. Prosim poskusite znova\n\n\n");iskanje(pod,fd);}
fclose(fd);
}
int main(void)
{
FILE *fd;
int a;
int menu;
printf("------------------------------------------------------------------------------- \n");
printf(" IMENIK \n");
printf("------------------------------------------------------------------------------- \n");
printf("Vnesi izbiro:\n");
printf("1.)Vpis podatkov\n");
printf("2.)Izpis vseh podatkov\n");
printf("3.)Iskanje po imenu ali priimku\n");
scanf("%d",&menu);
switch(menu)
{
case 1: vnos(pod,fd);
break;
case 2: izpis(pod,fd);
break;
case 3: iskanje(pod,fd);
break;
}
system("pause");
return 0;
}
well im now stucked cause i dont know how would i wrote more of adresess and details without overwriting previious ones. so i need to find where the inpts stops. and i also have problem to corectly do the fwrite and fread for multi-structure : example : pod[50](structure with more details).
so even explanation of anything above or example would be nice. also if you notice something that could be better please tell me
and im working with DEV-C++ on windows.
thanks for any kind of help in advance