beginner to intermediate

This is a discussion on beginner to intermediate within the C Programming forums, part of the General Programming Boards category; Hi, So i think i have passed the beginners level of c programming. My last program had a nice menu, ...

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

    beginner to intermediate

    Hi,
    So i think i have passed the beginners level of c programming. My last program had a nice menu, you input sets of data through options, it read from text files, saved to textfiles, did calculations and displayed it, used arrays etc.

    Now i want to try and learn some cooler stuff.

    My last program saved its output data to a text file, so the user could then input it to excel, and draw graphs. Is there a way i can open excel (assuming the location of it on the users computer) and input the data to cells there???

    Every time you closed my last program and re opened it, you had to reenter data, does anyone know a good way to have an "open recent" option?

    If i have a load of sets of data - a 100 say, please can you point me in the direction of drawing a text graph of those data points, with | __ as the axis and . as a point on the graph?

    Thanks guys

  2. #2
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    If you have a set of data . . . say, in an array of something much like this structure . . .
    Code:
    struct plot_point_t {
        double xpos, ypos;
    };
    . . . then, it's really quite simple. Well, relatively simple, anyhow . . .

    Assuming that xpos and ypos are both positive, find the maximum of both . . .

    Note that this is not completely valid C, just should give you an idea on how to do this kind of thing.
    Code:
    /* higher above: 
        size_t plots = 100;
        struct plot_point_t *points = malloc(sizeof(struct plot_point_t)*plots)
    */
    double xmax = 0.0, ymax = 0.0;
    size_t x;
    for(x = 0; x < plots; x ++) {
        if(points[x].xpos > xmax) xmax = plots[x].xpos;
    }
    /* . . . repeat above for the y axis . . . */
    for(x = 0; x < plots; x ++) {
        if(points[x].ypos > ymax) ymax = plots[x].ypos;
    }
    /* . . . now determine the scale . . . */
    /* assuming you've got 80x20 to work with here . . . use env[] to get the COLUMNS environment variable under *nix . . .*/
    int xres = xmax/80;
    int yres = ymax/20;
    int plotpositions[100][2]; /* NOTE: dynamically allocate this using the plots variable. just don't feel like doing a doubly-allocated array here . . . */
    for(x = 0; x < plots; x ++) {
        plotpositions[x][0] = (int)(points[x].xpos/xres);
        plotpositions[x][1] = (int)(points[x].ypos/yres);
    }
    /* now to paint them . . . */
    size_t y;
    for(y = 0; y < 20; y ++) {
        for(x = 0; x < 20; x ++) {
            size_t i;
            int printdot = 0;
            for(i = 0; i < plots; i ++) {
                if(plotpositions[i][0] == x && plotpositions[i][1] == y) printdot = 1;
            }
            if(printdot) putc('.');
            else putc(' ');
        }
    }
    Little lengthy, but it should be easy enough to follow. Note that a triply-nested loop is *not* the best way to do this, but is by far the easiest and simplest to follow.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Beginner Help On XP
    By rayne117 in forum C++ Programming
    Replies: 7
    Last Post: 01-07-2009, 12:45 PM
  2. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  3. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 10:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21