Wednesday, July 21, 2010

data set

I will soon get to a point where I need data to work with. See, most of the programs expect input of some kind (like a bunch of sentences to sort or count), but that's getting really annoying to type that in every time I want to test the program. I wonder if there is a way to have a text file at hand to pipe into the program. I might have to "cheat" and build in something to read the file (before I'm supposed to properly learn it) in the simple programs first.

I just hate having to use something over my head before I'm ready to use it. Maybe I'm being too strict. My "don't use it unless you really, really understand it" rule might be inhibiting me.

1 comment:

  1. A text file is good, but a header file might fit the bill too.

    Create a file (perhaps "mystrings.h") that looks like:


    char mystrings[][] = { "this is a sentence",
    "this is also a sentence" };


    Then, for each program that you want to use your string library with you can write:

    #include "mystrings.h"

    All of the variables you have declared in "mystrings.h" will be available to your program as global variables.

    ReplyDelete