split a source into many files, where each file contains a function of the source

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nilton
    New Member
    • Oct 2015
    • 2

    split a source into many files, where each file contains a function of the source

    does anyone know a program split a c source into many c files, where each c file contains a function of the initial c source?

    example:
    this file:
    Code:
    //file myprog.c ------------------
    #include<stdio.h>
    int a(int a, int b){
            return a+b;
    }
    
    int b(int a, int b){
            return a*b;
    }
    
    int main(){
            printf("a(10,10)=%d\n",a(10,10));
            printf("b(10,10)=%d\n",b(10,10));
    }
    //end of file myprog.c------------------------
    turn into these files:
    Code:
    //file a.h--------------------------------------------
    int a(int a, int b);
    //end of file a.h---------------------------------------
    
    // file a.c -------------------------------------------
    #include "a.h"
    
    int a(int a, int b){
            return a+b;
    }
    //end of file a.c--------------------------------------
    
    
    //file b.h-----------------------------------------
    int b(int a,int b);
    //end of file b.h---------------------------------
    
    //file b.c-------------------------------------------
    #include "b.h"
    
    int b(int a, int b){
            return a*b;
    }
    //end of file b.c----------------------------------
    
    //file main.c ------------------------------
    #include <stdio.h>
    #include "a.h"
    #include "b.h"
    
    int main(){
            printf("a(10,10)=%d\n",a(10,10));
            printf("b(10,10)=%d\n",b(10,10));
    }
    //end of file myprog.c ------------------------------

    thanks for the help!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    No, I don't.

    Usually, code is written in many source files each with a header so there's not much call for a program like that.

    Personally I would just build the files manually by cut/paste from the original file.

    Comment

    • Nilton
      New Member
      • Oct 2015
      • 2

      #3
      oh, then I have a big problem.
      I need to do this on some benchmarks, and one of these benchmarks has 288 ".c" files =/

      Comment

      Working...