Ahojte,
mam taky problem s mojim kodom. Nefunguje mi metoda void add() vid. kod nizsie, prosim kde mam chybu ?
void add()
{
FILE *outfile;
outfile=fopen("filmDatabase.dat","w");
if(outfile==NULL)
{
fprintf(stderr, "\nError opening filmDatabase.dat\n\n");
exit(1);
}
printf("Vlozte \"stop\" pre ukoncenie Filmoveho mena.");
while(1)
{
printf("\nNazov filmu - SK : ");
scanf("%s", input.fname);
if(strcmp(input.fname, "stop") == 0)
exit(1);
printf("Nazov filmu - EN : ");
scanf("%s", input.ename);
printf("Filmove cislo : ");
scanf("%d", &input.f_num);
fwrite(&input, sizeof(struct filmoteka), 1, outfile);
}
printf("CHCETE POKRACOVAT===>");
others=getche();
}
Okrem ineho mi hadze tieto errory,
error: stray '\302' in program
error: stray '\240' in program
Pripajam radsej cely zdrojak
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
struct filmoteka {
char fname[20];
char ename[20];
int f_num;
};
struct filmoteka input;
char others='y';
void add()
{
FILE *outfile;
outfile=fopen("filmDatabase.dat","w");
if(outfile==NULL)
{
fprintf(stderr, "\nError opening filmDatabase.dat\n\n");
exit(1);
}
printf("Vlozte \"stop\" pre ukoncenie Filmoveho mena.");
while(1)
{
printf("\nNazov filmu - SK : ");
scanf("%s", input.fname);
if(strcmp(input.fname, "stop") == 0)
exit(1);
printf("Nazov filmu - EN : ");
scanf("%s", input.ename);
printf("Filmove cislo : ");
scanf("%d", &input.f_num);
fwrite(&input, sizeof(struct filmoteka), 1, outfile);
}
printf("CHCETE POKRACOVAT===>");
others=getche();
}
void read()
{
FILE *infile;
infile = fopen ("filmDatabase.dat","r");
if (infile == NULL)
{
fprintf(stderr, "\nError opening filmDatabase.dat\n\n");
exit (1);
}
while(fread (&input, sizeof(struct filmoteka), 1, infile))
printf ("Filmove Meno = %10s %10s Filmove Cislo = %8d",
input.fname, input.ename, input.f_num);
getch();
}
int main()
{
char choice;
while(others=='y')
{
clrscr();
printf("\n\t\t Vyberte si z nasledujucich moznosti\n\n");
printf("\t\t\t 1.Pridaj nazov Filmu \n");
printf("\t\t\t 2.Zoznam Filmov \n");
printf("\t\t\t 3.Uprav zaznamy Filmov \n");
printf("\t\t\t 4.Vymaz Filmy \n");
printf("\t\t\t 5. Exit \n");
printf("\n\n\t\t\t Vasa volba: ");
choice=getche();
switch(choice)
{
case '1':
add();
break;
case '2':
read();
break;
case '3':
exit(0);
}
printf("CHCETE POKRACOVAT===>");
others=getche();
}
getch();
return 0;
}