C help - program doesnt work

this is suppose to be my final project in C, but as u will see it has a lot of bugs. It is similiar with a database where u can add , modify, delete a movie.The 1,2 and 3 I think it works but 4 and the rest doesnt, I watched in debugger and it says in some point that undefined symbol when trying to execute the function, but i dont know where should i define it.I dont have much experience in C, here is the code:

[code]
#include
#include
#include
#define MAX 100
char *menu [] =
{
"1. Add artistic movie",
"2. Add documentary",
"3. Add concert",
"4. All movies",
"5. All movies belonging to a director",
"6. All documentaries by theme",
"7. All concerts",
"8. Borrow a movie/doc/concert",
"9. Return a movie/doc/concert",
"10. All borrowings",
"11. Delete a movie",
"12. Nr of borrowings per month",
"13. Exit"
};


int SelectedIndex = 0;
int run = 1;
int nr = sizeof (menu) / sizeof (menu [0]);

typedef struct {

char title[50],name[50];
char director[50];
char borrowed[2];
int year,day,month;
int min;
int year_appearing;
int yeari,dayi,monthi;
} artistic;
int nr_artistic = 0;
artistic list[MAX];

typedef struct {
char dtitle[50],dname[50];
int dyear,dday,dmonth;
char dborrowed[2];
char theme[10];
int dmin;
int dyear_appearing;
int yeardoc,dayd,monthd;
} documentar;
int nr_documentar = 0;
documentar dlist[MAX];

typedef struct {
int cyear,cmonth,cday;
int cmin;
char location[20],cname[50],ctitle[50],cborrowed[2];
int nr_viewers;
char nr_play[100];
int yearc,dayc,monthc;
int yearconcert,dayconcert,monthconcert;
} concert;
int nr_concert = 0;
concert clist[MAX];

void read_sir(char *sir)
{
do {
gets(sir);
}
while (strlen (sir)==0);
}

void read(artistic *rez)
{
printf("Title:
");scanf("%s",&(rez->title));
printf("Director:
");scanf("%s",&(rez->director));
printf("Year appearing:
");scanf("%d",&(rez->year_appearing));
printf("Lenghts(min):
");scanf("%d",&(rez->min));
printf("Is borrowed? (d/n): ");scanf("%s",&(rez->borrowed));
if (*rez->borrowed=='d') {
printf("Name of person: ");scanf("%s",&(rez->name));
printf("Year Borrowed: ");scanf("%d",rez->yeari);
printf("Month Borrowed ");scanf("%d",rez->monthi);
printf("Day Borrowed: ");scanf("%d",rez->dayi);
printf("Year Return: ");scanf("%d",rez->year);
printf("Month Return ");scanf("%d",rez->month);
printf("Day Return: ");scanf("%d",rez->day);



}
}
void dread(documentar *drez)
{
printf("Title:
");scanf("%s",&(drez->dtitle));
printf("Year appearing:
");scanf("%d",&(drez->dyear_appearing));
printf("Lenghts(min):
");scanf("%d",&(drez->dmin));
printf("Theme:
");scanf("%s",&(drez->theme));
printf("Is borrowed? (d/n): ");scanf("%s",&(drez->dborrowed));
if (*drez->dborrowed=='d') {
printf("Name of person: ");scanf("%s",&(drez->dname));
printf("Year Borrowed: ");scanf("%d",drez->dyear);
printf("Month Borrowed: ");scanf("%d",drez->dmonth);
printf("Day Borrowed: ");scanf("%d",drez->dday);
printf("Year Return: ");scanf("%d",drez->yeardoc);
printf("Month Return: ");scanf("%d",drez->monthd);
printf("Day Return: ");scanf("%d",drez->dayd);
}
}
void cread(concert *crez)
{
int i,n;
printf("Title :
");scanf("%s",&(crez->ctitle));
printf("Year:
");scanf("%s",&(crez->yearconcert));
printf("Month:
");scanf("%s",&(crez->monthconcert));
printf("Day:
");scanf("%d",&(crez->dayconcert));
printf("Lenghts:(min)
");scanf("%d",&(crez->cmin));
printf("Location:
");scanf("%d",&(crez->location));
printf("Nr viewers:
");scanf("%d",&(crez->nr_viewers));
printf("What plays:
");scanf("%d",&n);
for (i=0;i<=n;i++)
scanf("%s",&(crez->nr_play[i]));
printf("Is borrowed? (d/n): ");scanf("%s",&(crez->cborrowed));
if (*crez->cborrowed=='d') {
printf("Name of person: ");scanf("%s",&(crez->cname));
printf("Year Borrowed: ");scanf("%d",crez->cyear);
printf("Month Borrowed: ");scanf("%d",crez->cmonth);
printf("Day Borrowed: ");scanf("%d",crez->cday);
printf("Year Return: ");scanf("%d",crez->yearc);
printf("Month Return: ");scanf("%d",crez->monthc);
printf("Day Return: ");scanf("%d",crez->dayc);

}
}
void write(artistic p)
{
printf("Title: %s, Director: %s, Year appearing: %d, Lenghts: %d
min",p.title,p.director,p.year_appearing,p.min);
if (*p.borrowed=='d') printf("Is borrowed to: %s, at de:%d.%d.%d, untill: %d.%d.%d
",
p.name,p.dayi,p.monthi,p.yeari,p.day,p.month,p.year);
else printf("is not borrowed
");
}
void dwrite(documentar q)
{
printf ("Title: %s, Year appeared: %d, Lenghts: %dmin, Theme: %s
",
q.dtitle, q.dyear, q.dmin, q.theme);
if (*q.dborrowed=='d') printf("Is borrowed to %s, at %d.%d.%d,until %d.%d.%d
",
q.dname,q.dday,q.dmonth,q.dyear,q.dayd,q.monthd,q.yeardoc);
else printf("is not borrowed
");
}
void cwrite(concert t)
{
printf("Title of the concert: %s,Date: %d.%d.%d, Lenghts: %dmin, Location: %s, Nr Viewers: %d, Nr_play: %s
",t.ctitle,t.dayconcert,t.monthconcert,t.yearconcert,t.cmin,t.nr_viewers,t.nr_play);
if(*t.cborrowed=='d') printf("Is borrowed to: %s, at %d.%d.%d, until: %d.%d.%d
",t.cname,t.cday,t.cmonth,t.cyear,t.dayc,t.monthc,t.yearc);
else printf("is not borrowed
");
}
void add (artistic p)
{
list[nr_artistic] = p;
nr_artistic++;
}
void dadd (documentar q)
{
dlist[nr_documentar] = q;
nr_documentar++;
}
void cadd(concert t)
{
clist[nr_concert] = t;
nr_concert++;
}

void write_list (void)
{
int i,j,k;
for (i=0;i<nr_artistic;i++)
write(list [i]);
for(j=0;j<nr_documentar;j++)
dwrite( dlist[j]);
for(k=0;k<nr_concert;k++)
cwrite(clist[k]);
if (nr_artistic == 0) printf ("There are no artistic movies in the database");
else if (nr_documentar ==0 ) printf("There are no documentaries in the database");
else if (nr_concert==0) printf("There are no concerts ");
else if ((nr_artistic == 0) && (nr_documentar==0) && (nr_concert==0)) printf("Empty database");
}
void write_concert(void)
{
int i;
for (i=0;i<= nr_concert;i++)
cwrite(clist[i]);
if (nr_concert == 0) printf("There are no concerts
");
}
void write_director(char *director)
{
int x=0;
int i=0;
printf("Name of director: ");read_sir(director);
while (i<nr_artistic)
{
if (strcmp(director, list[i].director) == 0 ) // returneaza 0 daca parametrii functiei sunt egali
{
write(list[i]);
x=1;
}
i++ ;
}
if (x==0) printf("Director %s doesn

Comments

  • : this is suppose to be my final project in C, but as u will see it
    : has a lot of bugs. It is similiar with a database where u can add ,
    : modify, delete a movie.The 1,2 and 3 I think it works but 4 and the
    : rest doesnt, I watched in debugger and it says in some point that
    : undefined symbol when trying to execute the function, but i dont
    : know where should i define it.I dont have much experience in C, here
    : is the code:
    :
    : [code]:
    : #include
    : #include
    : #include
    : #define MAX 100
    : char *menu [] =
    : {
    : "1. Add artistic movie",
    : "2. Add documentary",
    : "3. Add concert",
    : "4. All movies",
    : "5. All movies belonging to a director",
    : "6. All documentaries by theme",
    : "7. All concerts",
    : "8. Borrow a movie/doc/concert",
    : "9. Return a movie/doc/concert",
    : "10. All borrowings",
    : "11. Delete a movie",
    : "12. Nr of borrowings per month",
    : "13. Exit"
    : };
    :
    :
    : int SelectedIndex = 0;
    : int run = 1;
    : int nr = sizeof (menu) / sizeof (menu [0]);
    :
    : typedef struct {
    :
    : char title[50],name[50];
    : char director[50];
    : char borrowed[2];
    : int year,day,month;
    : int min;
    : int year_appearing;
    : int yeari,dayi,monthi;
    : } artistic;
    : int nr_artistic = 0;
    : artistic list[MAX];
    :
    : typedef struct {
    : char dtitle[50],dname[50];
    : int dyear,dday,dmonth;
    : char dborrowed[2];
    : char theme[10];
    : int dmin;
    : int dyear_appearing;
    : int yeardoc,dayd,monthd;
    : } documentar;
    : int nr_documentar = 0;
    : documentar dlist[MAX];
    :
    : typedef struct {
    : int cyear,cmonth,cday;
    : int cmin;
    : char location[20],cname[50],ctitle[50],cborrowed[2];
    : int nr_viewers;
    : char nr_play[100];
    : int yearc,dayc,monthc;
    : int yearconcert,dayconcert,monthconcert;
    : } concert;
    : int nr_concert = 0;
    : concert clist[MAX];
    :
    : void read_sir(char *sir)
    : {
    : do {
    : gets(sir);
    : }
    : while (strlen (sir)==0);
    : }
    :
    : void read(artistic *rez)
    : {
    : printf("Title:
    ");scanf("%s",&(rez->title));
    : printf("Director:
    ");scanf("%s",&(rez->director));
    : printf("Year appearing:
    ");scanf("%d",&(rez->year_appearing));
    : printf("Lenghts(min):
    ");scanf("%d",&(rez->min));
    : printf("Is borrowed? (d/n): ");scanf("%s",&(rez->borrowed));
    : if (*rez->borrowed=='d') {
    : printf("Name of person: ");scanf("%s",&(rez->name));
    : printf("Year Borrowed: ");scanf("%d",rez->yeari);
    : printf("Month Borrowed ");scanf("%d",rez->monthi);
    : printf("Day Borrowed: ");scanf("%d",rez->dayi);
    : printf("Year Return: ");scanf("%d",rez->year);
    : printf("Month Return ");scanf("%d",rez->month);
    : printf("Day Return: ");scanf("%d",rez->day);
    :
    :
    :
    : }
    : }
    : void dread(documentar *drez)
    : {
    : printf("Title:
    ");scanf("%s",&(drez->dtitle));
    : printf("Year appearing:
    ");scanf("%d",&(drez->dyear_appearing));
    : printf("Lenghts(min):
    ");scanf("%d",&(drez->dmin));
    : printf("Theme:
    ");scanf("%s",&(drez->theme));
    : printf("Is borrowed? (d/n): ");scanf("%s",&(drez->dborrowed));
    : if (*drez->dborrowed=='d') {
    : printf("Name of person: ");scanf("%s",&(drez->dname));
    : printf("Year Borrowed: ");scanf("%d",drez->dyear);
    : printf("Month Borrowed: ");scanf("%d",drez->dmonth);
    : printf("Day Borrowed: ");scanf("%d",drez->dday);
    : printf("Year Return: ");scanf("%d",drez->yeardoc);
    : printf("Month Return: ");scanf("%d",drez->monthd);
    : printf("Day Return: ");scanf("%d",drez->dayd);
    : }
    : }
    : void cread(concert *crez)
    : {
    : int i,n;
    : printf("Title :
    ");scanf("%s",&(crez->ctitle));
    : printf("Year:
    ");scanf("%s",&(crez->yearconcert));
    : printf("Month:
    ");scanf("%s",&(crez->monthconcert));
    : printf("Day:
    ");scanf("%d",&(crez->dayconcert));
    : printf("Lenghts:(min)
    ");scanf("%d",&(crez->cmin));
    : printf("Location:
    ");scanf("%d",&(crez->location));
    : printf("Nr viewers:
    ");scanf("%d",&(crez->nr_viewers));
    : printf("What plays:
    ");scanf("%d",&n);
    : for (i=0;i<=n;i++)
    : scanf("%s",&(crez->nr_play[i]));
    : printf("Is borrowed? (d/n): ");scanf("%s",&(crez->cborrowed));
    : if (*crez->cborrowed=='d') {
    : printf("Name of person: ");scanf("%s",&(crez->cname));
    : printf("Year Borrowed: ");scanf("%d",crez->cyear);
    : printf("Month Borrowed: ");scanf("%d",crez->cmonth);
    : printf("Day Borrowed: ");scanf("%d",crez->cday);
    : printf("Year Return: ");scanf("%d",crez->yearc);
    : printf("Month Return: ");scanf("%d",crez->monthc);
    : printf("Day Return: ");scanf("%d",crez->dayc);
    :
    : }
    : }
    : void write(artistic p)
    : {
    : printf("Title: %s, Director: %s, Year appearing: %d, Lenghts: %d
    min",p.title,p.director,p.year_appearing,p.min);
    : if (*p.borrowed=='d') printf("Is borrowed to: %s, at de:%d.%d.%d, untill: %d.%d.%d
    ",
    : p.name,p.dayi,p.monthi,p.yeari,p.day,p.month,p.year);
    : else printf("is not borrowed
    ");
    : }
    : void dwrite(documentar q)
    : {
    : printf ("Title: %s, Year appeared: %d, Lenghts: %dmin, Theme: %s
    ",
    : q.dtitle, q.dyear, q.dmin, q.theme);
    : if (*q.dborrowed=='d') printf("Is borrowed to %s, at %d.%d.%d,until %d.%d.%d
    ",
    : q.dname,q.dday,q.dmonth,q.dyear,q.dayd,q.monthd,q.yeardoc);
    : else printf("is not borrowed
    ");
    : }
    : void cwrite(concert t)
    : {
    : printf("Title of the concert: %s,Date: %d.%d.%d, Lenghts: %dmin, Location: %s, Nr Viewers: %d, Nr_play: %s
    ",t.ctitle,t.dayconcert,t.monthconcert,t.yearconcert,t.cmin,t.nr_viewers,t.nr_play);
    : if(*t.cborrowed=='d') printf("Is borrowed to: %s, at %d.%d.%d, until: %d.%d.%d
    ",t.cname,t.cday,t.cmonth,t.cyear,t.dayc,t.monthc,t.yearc);
    : else printf("is not borrowed
    ");
    : }
    : void add (artistic p)
    : {
    : list[nr_artistic] = p;
    : nr_artistic++;
    : }
    : void dadd (documentar q)
    : {
    : dlist[nr_documentar] = q;
    : nr_documentar++;
    : }
    : void cadd(concert t)
    : {
    : clist[nr_concert] = t;
    : nr_concert++;
    : }
    :
    : void write_list (void)
    : {
    : int i,j,k;
    : for (i=0;i<nr_artistic;i++)
    : write(list [i]);
    : for(j=0;j<nr_documentar;j++)
    : dwrite( dlist[j]);
    : for(k=0;k<nr_concert;k++)
    : cwrite(clist[k]);
    : if (nr_artistic == 0) printf ("There are no artistic movies in the database");
    : else if (nr_documentar ==0 ) printf("There are no documentaries in the database");
    : else if (nr_concert==0) printf("There are no concerts ");
    : else if ((nr_artistic == 0) && (nr_documentar==0) && (nr_concert==0)) printf("Empty database");
    : }
    : void write_concert(void)
    : {
    : int i;
    : for (i=0;i<= nr_concert;i++)
    : cwrite(clist[i]);
    : if (nr_concert == 0) printf("There are no concerts
    ");
    : }
    : void write_director(char *director)
    : {
    : int x=0;
    : int i=0;
    : printf("Name of director: ");read_sir(director);
    : while (i<nr_artistic)
    : {
    : if (strcmp(director, list[i].director) == 0 ) // returneaza 0 daca parametrii functiei sunt egali
    : {
    : write(list[i]);
    : x=1;
    : }
    : i++ ;
    : }
    : if (x==0) printf("Director %s doesn
  • [color=Blue]To see these warnings in Turbo C go: Options -> Compiler -> Messages -> Display -> All[/color]
  • the program compiles but when i try to hit to show all movies it doesnt do anything. This happens with the rest too,it doesnt show me what`s in the database, nothing happens when i press enter,not even an error.
  • : the program compiles but when i try to hit to show all movies it
    : doesnt do anything. This happens with the rest too,it doesnt show me
    : what`s in the database, nothing happens when i press enter,not even
    : an error.
    :
    [color=Blue]Did you fix the issues with "=="?[/color]
  • does
    [code]
    if(*list[i].borrowed = 'd')
    [/code]
    this has to be
    [code]
    if(*list[i].borrowed == 'd')
    [/code]
    too.
    The rest is == all over the place,as far as i see.

    I watched in debugged , I put a breakpoint in line 484, then steped into with F7 (there were no movies in the database so i=0 and nr_artistic=0) then there is a
    [code] if (nr_artistic == 0) printf ("There are no artistic movies in the database");
    [/code]
    at line 180, but the line doesnt get executed, it doesnt print anything on the screen like it suppose to
  • : then there is a
    : [code]: if (nr_artistic == 0) printf ("There are no artistic movies in the database");
    : [/code]:
    : at line 180, but the line doesnt get executed, it doesnt print
    : anything on the screen like it suppose to
    Actually, it does print the line on the screen, but you don't see it because the program quickly moves on without pause, clears the screen and rewrites the main menu.



  • [color=Blue]Very good point! Insert the line to wait AFTER menu command is executed and then start investigating:[/color]
    [code]
    switch(j)
    {
    case 0: //daca is 0 atunci getch asteapta o a
    //doua valoare,care de ex code 80 pt sageata in jos

    refresh = getchtasta (getch ()); //ia valoarea din parametrul functiei getchtasta(), daca e 1 sa schimbat indexu
    break;

    case 13:
    Execute();
    [color=Red]printf("

    *** PRESS ANY KEY: ");getch();[/color]
    break;
    }
    }
    [/code]
  • : [color=Blue]Very good point! Insert the line to wait AFTER menu
    : command is executed and then start investigating:[/color]
    : [code]:
    : switch(j)
    : {
    : case 0: //daca is 0 atunci getch asteapta o a
    : //doua valoare,care de ex code 80 pt sageata in jos
    :
    : refresh = getchtasta (getch ()); //ia valoarea din parametrul functiei getchtasta(), daca e 1 sa schimbat indexu
    : break;
    :
    : case 13:
    : Execute();
    : [color=Red]printf("

    *** PRESS ANY KEY: ");getch();[/color]
    : break;
    : }
    : }
    : [/code]:
    Before ur reply i actualy edited and typed getch(); at the end of all functions, :( stupid me it was a lot easier as u said , but it works either way.
    Oke now it compiles and works, it still has a few bugs but i will work on it. Nr 10 doesnt work and i still didnt do nr 12.

    One major aspect, in the requirements says i have to load the data from a file and at the exit save the data into a file.
    I was thinking for saving the data:
    [code]
    FILE *f
    f = fopen ("artistic.txt",w);
    if (f== NULL) printf("error");
    else
    {
    fwrite(lista, sizeof(artistic),1,f);
    fclose(f);
    }
    [/code]
    Is this oke ? Do i have to do 3 files, or is it posible to write all struct to the same file?
    and for loading the data from the file
    [code]
    FILE *f
    int i,n;
    f = fopen ("artistic.txt",r);
    if (f== NULL) printf("error");
    else
    {
    n=fread(lista, sizeof(artistic),MAX,f);
    for (i=0;i<n,i++)
    {
    printf("Title: %s
    ",i+1,lista[i].title);
    //..................... all members of the structure
    }
    fclose(f);
    }
    [/code]



  • [code]
    void save ()
    {
    FILE* f = fopen ("database.bin", "wb");
    if (!f) return;

    fwrite (&nr_artistic, sizeof (int), 1, f);
    fwrite (&nr_documentar, sizeof (int), 1, f);
    fwrite (&nr_concert, sizeof (int), 1, f);

    fwrite (list, sizeof (list), 1, f);
    fwrite (dlist, sizeof (dlist), 1, f);
    fwrite (clist, sizeof (clist), 1, f);

    fclose (f);
    }

    void load ()
    {
    FILE* f = fopen ("database.bin", "rb");
    if (!f) return;

    fread (&nr_artistic, sizeof (int), 1, f);
    fread (&nr_documentar, sizeof (int), 1, f);
    fread (&nr_concert, sizeof (int), 1, f);

    fread (list, sizeof (list), 1, f);
    fread (dlist, sizeof (dlist), 1, f);
    fread (clist, sizeof (clist), 1, f);

    fclose (f);
    }
    [/code]
  • : [code]:
    : void save ()
    : {
    : FILE* f = fopen ("database.bin", "wb");
    : if (!f) return;
    :
    : fwrite (&nr_artistic, sizeof (int), 1, f);
    : fwrite (&nr_documentar, sizeof (int), 1, f);
    : fwrite (&nr_concert, sizeof (int), 1, f);
    :
    : fwrite (list, sizeof (list), 1, f);
    : fwrite (dlist, sizeof (dlist), 1, f);
    : fwrite (clist, sizeof (clist), 1, f);
    :
    : fclose (f);
    : }
    :
    : void load ()
    : {
    : FILE* f = fopen ("database.bin", "rb");
    : if (!f) return;
    :
    : fread (&nr_artistic, sizeof (int), 1, f);
    : fread (&nr_documentar, sizeof (int), 1, f);
    : fread (&nr_concert, sizeof (int), 1, f);
    :
    : fread (list, sizeof (list), 1, f);
    : fread (dlist, sizeof (dlist), 1, f);
    : fread (clist, sizeof (clist), 1, f);
    :
    : fclose (f);
    : }
    : [/code]:
    thanks, it saves the data and when i run the program later the data is there, but my question is this.the filename database.bin is empty, 0 kb, even when i remove it the program still saves the data in memory i guess, thats my question,why the file is 0 kb when it suppose to have the data in it.
  • : : [code]: :
    : : void save ()
    : : {
    : : FILE* f = fopen ("database.bin", "wb");
    : : if (!f) return;
    : :
    : : fwrite (&nr_artistic, sizeof (int), 1, f);
    : : fwrite (&nr_documentar, sizeof (int), 1, f);
    : : fwrite (&nr_concert, sizeof (int), 1, f);
    : :
    : : fwrite (list, sizeof (list), 1, f);
    : : fwrite (dlist, sizeof (dlist), 1, f);
    : : fwrite (clist, sizeof (clist), 1, f);
    : :
    : : fclose (f);
    : : }
    : :
    : : void load ()
    : : {
    : : FILE* f = fopen ("database.bin", "rb");
    : : if (!f) return;
    : :
    : : fread (&nr_artistic, sizeof (int), 1, f);
    : : fread (&nr_documentar, sizeof (int), 1, f);
    : : fread (&nr_concert, sizeof (int), 1, f);
    : :
    : : fread (list, sizeof (list), 1, f);
    : : fread (dlist, sizeof (dlist), 1, f);
    : : fread (clist, sizeof (clist), 1, f);
    : :
    : : fclose (f);
    : : }
    : : [/code]: :
    : thanks, it saves the data and when i run the program later the data
    : is there, but my question is this.the filename database.bin is
    : empty, 0 kb, even when i remove it the program still saves the data
    : in memory i guess, thats my question,why the file is 0 kb when it
    : suppose to have the data in it.
    :
    [color=Blue]
    This should not happen. How do you see the file size?
    [/color]
  • hmmz i think i got the wrong idea, oke so i learned at school that i have to manually create a file, in this case database.bin.In our school examples when we fwrite() and then open the file it has some data in it.

    Maybe i cant see any data cus the file i created is never used.

    Is the program creating its own file ? Thats the case i was looking in the wrong file, where is the right file ? or that file cant be accessed.Sorry for all the questions but i wanna understand how it works.


  • : hmmz i think i got the wrong idea, oke so i learned at school that i
    : have to manually create a file, in this case database.bin.In our
    : school examples when we fwrite() and then open the file it has some
    : data in it.
    :
    : Maybe i cant see any data cus the file i created is never used.
    :
    : Is the program creating its own file ? Thats the case i was looking
    : in the wrong file, where is the right file ? or that file cant be
    : accessed.Sorry for all the questions but i wanna understand how it
    : works.
    :
    :
    :
    [color=Blue]Here is how it works: when you open a file - system makes it zero bytes and allocates a memory buffer for the file. This memory buffer is called a cache and it is needed to provide a faster fwrite() call. When you call fwrite() - bytes are going into that buffer and not physically into the file. The buffer dumped into a file when that cache buffer is overflown. System writes (this time physically) to file and clears the cache buffer, so fwrite() can fill it again. fclose() will flush the cache buffer remaining bytes and close the physical file. Look at the size AFTER fclose() call.[/color]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories