Thread: Splitting source code files

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    8

    Splitting source code files

    I have a program that I want to split into two separate source code files, plus a single header file. The first source file should just have the main function that takes care of the input and calls the manipulation function. The header should contain the interface to those functions that the main function can then include.

    Here's the code I have so far:

    Code:
    #include<stdio.h>
    
    void update(char);
    void print_hist(void);
    
    int main(void)
    {
      char c;
    
      printf("Please enter as many characters as you would like. Press enter or send the EOF character when you are done.\n");
     
      while( (c=getchar()) != EOF) {
        void update(char);
        void print_hist(void);
      }
    
      return 0;
    }
    Thanks!

    EDIT: I'm working on the manipulation functions now. However, I can't figure out how to make the void update(char) determine whether a character is alphanumeric or not. Can anyone give me some direction?
    Last edited by rocksteady; 10-19-2007 at 01:48 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Take this and put it in the header:
    Code:
    void update(char);
    void print_hist(void);
    Replace those lines in the main file with an include of the header. Take the implementations of those functions and put them in a .c file. Correct your main function like so:
    Code:
    while( (c=getchar()) != EOF) {
        update(c);
        print_hist();
    }
    That's all it takes to separate things into three files.

    >I can't figure out how to make the void update(char)
    >determine whether a character is alphanumeric or not.
    I'm rather partial to the standard isalnum function.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Thank you. I was confused on how to insert the call functions, but that's because I didn't really know what a header file was.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do you call another source code file?
    By nifear4 in forum C Programming
    Replies: 2
    Last Post: 10-28-2008, 12:16 PM
  2. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  3. Splitting Code Into Multiple Files
    By pobri19 in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2008, 04:21 AM
  4. Search for patterns in source code
    By MiamiCuse in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-23-2005, 11:28 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM