#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;
void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod. ime);
printf("Vnesi priimek: "); scanf("%s",pod. priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod .ucni_uspeh);
printf("Vnesi ulico in st.: "); fgets(pod.ulica ,100,fd); //scanf("%s",pod. ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod. mesto);
printf("Vnesi tel st: "); scanf("%s",pod. tel_st);
fd=fopen("DIJAK I.BIN","a");
fwrite(&pod,siz eof(pod),1,fd);
fclose(fd);
}
void izpis(struct oseba pod,FILE *fd)
{
fd=fopen("DIJAK I.BIN","r");
fread(&pod,size of(pod),1,fd);
fclose(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("Telefon ska stevilka: %s\n",pod.tel_s t);
}
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.)Izpi s vseh podatkov\n");
printf("3.)Iska nje po imenu ali priimku\n");
scanf("%d",&men u);
switch(menu)
{
case 1: vnos(pod,fd);
break;
case 2: izpis(pod,fd);
break;
}
system("pause") ;
return 0;
}
heres the code :
void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod. ime);
printf("Vnesi priimek: "); scanf("%s",pod. priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod .ucni_uspeh);
printf("Vnesi ulico in st.: "); fgets(pod.ulica ,100,fd);//here is the problem
//scanf("%s",pod. ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod. mesto);
printf("Vnesi tel st: "); scanf("%s",pod. tel_st);
fd=fopen("DIJAK I.BIN","a");
fwrite(&pod,siz eof(pod),1,fd);
fclose(fd);
}
well i have problem when trying to scan a string longer then one word for example: railroad 25
with normal scan i can rea only first word and i dont know how to correct this mistake so im asking for help.
#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;
void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod. ime);
printf("Vnesi priimek: "); scanf("%s",pod. priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod .ucni_uspeh);
printf("Vnesi ulico in st.: "); fgets(pod.ulica ,100,fd); //scanf("%s",pod. ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod. mesto);
printf("Vnesi tel st: "); scanf("%s",pod. tel_st);
fd=fopen("DIJAK I.BIN","a");
fwrite(&pod,siz eof(pod),1,fd);
fclose(fd);
}
void izpis(struct oseba pod,FILE *fd)
{
fd=fopen("DIJAK I.BIN","r");
fread(&pod,size of(pod),1,fd);
fclose(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("Telefon ska stevilka: %s\n",pod.tel_s t);
}
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.)Izpi s vseh podatkov\n");
printf("3.)Iska nje po imenu ali priimku\n");
scanf("%d",&men u);
switch(menu)
{
case 1: vnos(pod,fd);
break;
case 2: izpis(pod,fd);
break;
}
system("pause") ;
return 0;
}
heres the code :
void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod. ime);
printf("Vnesi priimek: "); scanf("%s",pod. priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod .ucni_uspeh);
printf("Vnesi ulico in st.: "); fgets(pod.ulica ,100,fd);//here is the problem
//scanf("%s",pod. ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod. mesto);
printf("Vnesi tel st: "); scanf("%s",pod. tel_st);
fd=fopen("DIJAK I.BIN","a");
fwrite(&pod,siz eof(pod),1,fd);
fclose(fd);
}
well i have problem when trying to scan a string longer then one word for example: railroad 25
with normal scan i can rea only first word and i dont know how to correct this mistake so im asking for help.
Comment