Thread: Run function from text file

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    1

    Question Run function from text file

    I need to run different sequences of function. Each sequence will be saved into a text file. My problem is how can I run the function by reading the text file ?

    For example : I have 3 functions : sum (int i, int j), average(int i, int j), logic (int i, int j). I made a text file and the content is : sum, average, logic. When my program read this text file, it will run function sum, follow by average and then logic.

    Question : How to call those function from text file ?

    Regards,
    Hendra

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    One way:
    Read each line into memory (fgets), then use strcmp() to compare the string against your list of known functions, and invoke the appropriate one.

    Code:
    fgets(buf, ......)
    if (strcmp(buf, "average") == 0)
    {
      invoke_average();
    }
    
    etc etc
    Naturally the above is simplistic. You'll need to make the code a bit smarter to actually work, that's a good challenge, right?!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM