file

Thread Starter

eggtree

Joined Nov 28, 2006
27
Hi,

I would like to got advise on how to create and store file using C++.

example: write a C++ program on daily expanses for every month
(1)
day1- total expanse = $10
day2- total expanse = $12
.
.
.
.
.
.
day30- total expanse = $15

Total expanse report for month of june is $400.


(2)
prompt user:
Enter any month expanse:June

day1- total expanse = $10
day2- total expanse = $12
.
.
.
.
.
.
day30- total expanse = $15

I will write the rest of the program but I do not know how to store the data and rertrive the data.

Any simple sample of this type of program for reference?
 

Thread Starter

eggtree

Joined Nov 28, 2006
27
im still not able to find the templete for the read write and read prgram.

Pls enlighten me.Thxs.

I got something close but its not the right one.

#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE 100

int main()
{
char buf[BUFSIZE];
char filename[60];
FILE*fp;

puts("Enter name of text file to display:");
gets(filename);

if((fp = fopen(filename,"r"))==NULL)
{
fprintf(stderr, "Error opening file.");
exit;
}

while (!feof(fp))
{
fgets(buf,BUFSIZE,fp);
printf("%s",buf);
}

fclose(fp);

return 0;
}
 
Top