Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:28:58+00:00 2026-06-13T23:28:58+00:00

Suppose you created a main() to deal with an exercise you asked your students.

  • 0

Suppose you created a main() to deal with an exercise you asked your students.

Every student is supposed to write their own function, with the same API. And a single file will be created, with all functions and the main calling them.

Lets say: int studentname(int a, int b) is the function pattern.

One way I deal with it was using a vector of pointer to functions int (*func[MAX])(). But you need to fulfill the vector one by one func[0]=studentname;.

I wonder, is there a way a function can be called by its name somehow?

Something like: int student1(int a , int b), student2(), etc.

And in main somehow we could just call sscanf(funcname,"student%d",i); funcname();.

Do you have any other idea? Maybe

int studentname(int a, int b, char *fname)
{
    strcpy(fname, "studentname");

Anything creative will do! 🙂

Thanks!
Beco

PS. I tried just a vector of functions, but C won’t allow me! 🙂

int func[2]()={{;},{;}};

This way I could just give to each student a number, and voilá… But no way. It was funny though.


Edited: I’m using linux.

Edited 2: Thanks! I’ve accepted an answer that helped me, but I’ve also documented a complete example as an answer bellow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:29:00+00:00Added an answer on June 13, 2026 at 11:29 pm

    Maybe a bit overcomplicating it, but spontaneous idea:

    • Compile all student source files into one shared library with the students’ functions being exports.
    • Then enumerate all exposed functions, call and test them.

    As an alternative:

    • Write a small tool that will compile all “student units” using a preprocessor define to replace a predefined function name with an unique name (“func1”, “func2”, etc.).
    • Then let the tool write a small unit calling all these functions while performing tests, etc.

    And yet another idea:

    • Use C++ to write a special class template that’s going to register derived classes in a object factory and just embed student’s code using extern "C". Depending on the implementation this might look a bit confusing and overcomplicated though.
    • Then use the factory to create one instance of each and run the code.

    Example for the approach with dlopen() and dlsym() (whether only one function per library or all – doesn’t matter):

    void *pluginlib = dlopen("student1.so", RTLD_NOW); // RTLD_NOW will load the file right away
    if (!pluginlib)
        ; // failed to load
    studentproc func = (studentproc)dlsym(pluginlib, "student1"); // this loads the function called "student1"
    if (!func)
        ; // failed to resolve
    func("hello world!"); // call the lib
    dlclose(pluginlib); // unloads the dll (this will make all further calls invalid)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have created one jQuery function to check if elements exist or not
Suppose I just created a package example and have two classes inside it, Main
Suppose there are two threads, the main thread and say thread B(created by main).
Suppose I created index with descending order CREATE INDEX `MyTable.MyIndex` USING BTREE ON `MyTable`
Suppose I created a cookie with one year expiration in domain abc.com and now
What is the best practice for releasing a simple software? Suppose I created a
Suppose I have created a UIView , MyView , in Interface Builder, and I
Suppose an application with some forms and only one data module are created at
Let us suppose I have a table created as follows: create table `test_table` (
I've created a web page that is suppose to look like it has tabs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.