Thread: help menu

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    204

    help menu

    Hi at the moment my program takes in 6 strings and saves them to a text file.

    Each time it saves to text file, the line changes to something like this

    a = 1, b = 2, c = 3, Xo = 4, Yo = 5, Zo = 6,

    How can i change the code so instead of deleting the last line that is there it adds a line ABOVE it so you get

    a = 7, b = 8, c = 9, Xo = 10, Yo = 11, Zo = 12,
    a = 1, b = 2, c = 3, Xo = 4, Yo = 5, Zo = 6,

    and how can i make it only ever have 6 lines in the file. (the file is a recent data file, so instead of a user having to type data in everytime, the user can see data used before - the last 6 times).

    And last question - to recall this data, what is the best way to do it - can i get the computer to notice the commas, and store the number just before it into a float?

    thanks:

    Code:
    char *options[100], *a[100], *b[100], *c[100], *Xo[100], *Yo[100], *Zo[100];
        FILE *recentdata;
        printf("Please input a, b and c, or type 'recent' to see a list of recently used data.\n");
    
        scanf("%99s", options);
        if(strcmpi(options,"recent") == 0)//compare options to "recent" NOT case sensitive.
        {
            //write a function for recent
            printf("finding recent files");
        }
    else
    {
        strcpy(a,options);
        scanf("%99s", b);
        scanf("%99s", c);
        printf ("%s %s %s\n\n", a, b, c);
    
        printf("Please input Xo, Yo and Zo\n");
        scanf("%99s", Xo);
        scanf("%99s", Yo);
        scanf("%99s", Zo);
        printf ("%s %s %s\n\n", Xo, Yo, Zo);
    
        printf("Executing Improved Euler...");
    }
        recentdata = fopen("recentdata.txt", "w");
        fprintf(recentdata, "a = %s, b = %s, c = %s, Xo = %s, Yo = %s, Zo = %s,\n", a, b, c, Xo, Yo, Zo);
        fclose;
        return 0;

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by a.mlw.walker View Post
    How can i change the code so instead of deleting the last line that is there it adds a line ABOVE it so you get

    and how can i make it only ever have 6 lines in the file. (the file is a recent data file, so instead of a user having to type data in everytime, the user can see data used before - the last 6 times).
    you cannot insert data in the middle of the file without overwriting part of it.

    if you want to store 6 lines of data in the file -

    make array of 6 lines, fill line[0] with new data, (sprintf will help)

    read line[1]-line[5] from the file, (fgets)
    and then - overwrite the whole file with the 6 lines you have
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM