By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

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

P: 2
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:
Expand|Select|Wrap|Line Numbers
  1. //file myprog.c ------------------
  2. #include<stdio.h>
  3. int a(int a, int b){
  4.         return a+b;
  5. }
  6.  
  7. int b(int a, int b){
  8.         return a*b;
  9. }
  10.  
  11. int main(){
  12.         printf("a(10,10)=%d\n",a(10,10));
  13.         printf("b(10,10)=%d\n",b(10,10));
  14. }
  15. //end of file myprog.c------------------------
  16.  
turn into these files:
Expand|Select|Wrap|Line Numbers
  1. //file a.h--------------------------------------------
  2. int a(int a, int b);
  3. //end of file a.h---------------------------------------
  4.  
  5. // file a.c -------------------------------------------
  6. #include "a.h"
  7.  
  8. int a(int a, int b){
  9.         return a+b;
  10. }
  11. //end of file a.c--------------------------------------
  12.  
  13.  
  14. //file b.h-----------------------------------------
  15. int b(int a,int b);
  16. //end of file b.h---------------------------------
  17.  
  18. //file b.c-------------------------------------------
  19. #include "b.h"
  20.  
  21. int b(int a, int b){
  22.         return a*b;
  23. }
  24. //end of file b.c----------------------------------
  25.  
  26. //file main.c ------------------------------
  27. #include <stdio.h>
  28. #include "a.h"
  29. #include "b.h"
  30.  
  31. int main(){
  32.         printf("a(10,10)=%d\n",a(10,10));
  33.         printf("b(10,10)=%d\n",b(10,10));
  34. }
  35. //end of file myprog.c ------------------------------
  36.  

thanks for the help!
Oct 30 '15 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Oct 30 '15 #2

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

Post your reply

Sign in to post your reply or Sign up for a free account.