Need Help With Header library file..

This is a discussion on Need Help With Header library file.. within the C Programming forums, part of the General Programming Boards category; Hi everybody! im hoping someone can plz help me out. I have to write a C program that reads in ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Need Help With Header library file..

    Hi everybody! im hoping someone can plz help me out. I have to write a C program that reads in an English language message and encode that message into a Morse code, and vice versa. The user should have the option of inputting the message from a file with the path given on the command line or directly from the keyboard.

    The following specifications apply:
    1. Use one blank space between each Morse coded letter and three blanks between each Morse coded word.
    2. Use the normal single space between English words and no space between English letters.
    3. The program must be implemented with a programmer defined code converter library. For example, you may implement the library morseconverter. If so, then there must be a morseconverter.h header file and a morseconverter.c implementation file developed for the library.
    4. Your program must implement structures for each code. For example, a structure will contain the English character S and the equivalent code . . . at a minimum to store the code for English S. This structure must be defined in the programmer defined library at Specification 3 above.
    5. The program output will be:
    a) A printout of the converted message on screen, and
    b) A text file with the original message to the top followed by the converted message.

    the problem is dat i have very basic knowledge in c programming, and im asking someone to plz help me create the header/library file and the .c file....i would very much appriciate it
    thank u

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    You need to make an attempt yourself
    C Board - Announcements in Forum : General Programming Boards

    First start small
    A development process
    Ignore the Morse bit for now, just try reading input from the user and print it back.
    When that is done, then try printing each letter.
    Then perhaps some specific examples of Morse translation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    the problem for me is implimenting the header file, dat i dont know.
    basically i think i can make this work without the header, using 2 sepearte blocks one for english to mores and anothe for morse to english with basic asigning and maybe a switch construct, but would be plenty coding and also the major aspect of the program is to impliment your own header file.....was hoping to get some helpwith dat part....i would have done the main function.....

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    Moving the code to a separate source file (and it's accompanying header file) is something which is easy to do later (just a copy/paste job).

    First you edit your code so what you want to separate out is in a function (or set of related functions).

    Say you have main.c like this.
    Code:
    #include <stdio.h>
    
    void func ( char *msg ) {
      printf( "%s\n", msg );
    }
    
    int main ( ) {
      func("hello");
      return 0;
    }
    After editing, you have 3 files.
    This is func.h
    Code:
    #ifndef FUNC_H_INCLUDED
    #define FUNC_H_INCLUDED
    
    void func ( char *msg );
    #endif
    This is func.c
    Code:
    #include <stdio.h>
    #include "func.h"
    
    void func ( char *msg ) {
      printf( "%s\n", msg );
    }
    And this is main.c
    Code:
    #include <stdio.h>
    #include "func.h"
    
    int main ( ) {
      func("hello");
      return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    hey after lots of trying i was able to come up wit this, its working from command line, but i can only convert from english to morse,
    can u please tell me where im going wrong and how to make it convert from morse to english?
    thanks

    Code:
     
    Last edited by kensam; 01-27-2010 at 06:04 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    What exactly do you type in when trying to convert from Morse to English?

    I see a memcmp, which isn't exactly what I would suggest for comparing strings.

    Also, how do you know the letter boundaries of your Morse string?

    morse -d ...---...
    is a lot different to
    morse -d "... --- ..."

    Morse isn't an unambiguous grammar, you can't tell what the next letter is just from looking at the tokens. There has to be a separator.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    the seperator suppose to be a single space, that is, -d "... --- ... "
    And how would u propose dat i should compare strings? strcmp??

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    So where in your code do you detect spaces in the decode function.

    And yes, strcmp().
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    5
    hey ne way, thanks for ur reply...but i wll have to work wit wat i have here, this stuff due 2morrow, so i dont hve ne more time to work on it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 02:19 PM
  4. Replies: 6
    Last Post: 04-02-2002, 05:46 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21