file

Discussion in 'Programmer's Corner' started by eggtree, Jun 10, 2007.

  1. eggtree

    Thread Starter Member

    Nov 28, 2006
    27
    0
    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?
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    There are many tutorials on the Internet that can shed light on this topic. Here is one example of such a tutorial.

    hgmjr
     
  3. eggtree

    Thread Starter Member

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

    Pls enlighten me.Thxs.
     
  4. eggtree

    Thread Starter Member

    Nov 28, 2006
    27
    0
    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;
    }
     
Loading...