Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to write a C programming proposal?

  1. May 6, 2012 #1
    I'm new at C programming. My course required me to write a proposal with the title "Word Processing'. It sounds: Create an interface that emulates basic word processing. Ask the
    user to input text and save it to "txt" format. The user should be
    able to modify, add and remove any of the sentences. You can
    limit the sentence length.- My problem here is developing an algorithm.
     
  2. jcsd
  3. May 6, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey yukari1310 and welcome to the forums.

    The first thing you will need to do is to develop an interface.

    The interface is basically going to consist of a bunch of functions and data structures that you will use for your project. You will have to think of all the data that passes to and from the function and declare everything that is going to publically available to the program as well as all your data structures that are in the interface functions.

    You will have to know what you are doing to create this interface and even before you write code. The structures and the interface will relate to what you actually need to do.

    Some advice for you is to think about what the data is, how you want to modify or filter it and what specific functionality you need to implement and how that affects the data in the data structures.
     
  4. May 7, 2012 #3
    I need the solution asap cause i have to submit the proposal by this friday... can anyone out there help me?
     
  5. May 7, 2012 #4

    chiro

    User Avatar
    Science Advisor

    We don't do work for people, but following on from what I said above translate the requirements into functions and data and then write them out using structs and functions and that will be your interface.
     
  6. May 7, 2012 #5

    rcgldr

    User Avatar
    Homework Helper

    Do you need to write the code or just the proposal about the code? It appears that this word processor operates on a group of sentences. Once data is entered (or read from a file), it's not clear how the user will specify which sentence to change. Removing and inserting sentences will not be difficult, but "modifying" sentences could mean that you'd have to create an user interface that allows a user to insert, replace, or delete characters in a sentence. This user interface would be system specific (unix, dos console window, windows text box, ...).
     
  7. May 8, 2012 #6
    Yes. It is the code that i need. What's the different between removing/inserting and modifying? they sound the same to me
     
  8. May 8, 2012 #7

    chiro

    User Avatar
    Science Advisor

    An interface is not the same as the actual code: it is only the implementation details for an external user to 'do stuff'.

    This is a common thing in software development. What usually happens is that you need to do something that you don't have time for, or the expertise to do so you get someone else to write stuff that allows them to do what you need to without knowing how it actually works (but you know what it will do for your needs).

    This is what an interface is: it's basically a published set of all the routines and data structure definitions that the functions use. It contains no code: only these things.

    Then what you do is you supply all the data and arguments for the routines and it will spit back the results plus say if an error occured.

    You will need to know this like the back of your hand if you ever do software development for a living, because this is what goes on all the time.

    Again you don't need to supply the code (yet) to actually do all the stuff but you need to think of the functions and the data structures that will available to the outside coder so that they can do what you've been asked to help them do.

    If you are having trouble with understanding this think of header files (.h) vs the code (.c, .cpp). This will make things a lot easier if you understand this kind of thing.
     
  9. May 8, 2012 #8
    Can you show me an example of interface?
     
  10. May 8, 2012 #9

    chiro

    User Avatar
    Science Advisor

    Here is a really simple one for a file system:

    Code (Text):


    // Sample interface for file I/O. Assume strings are ANSI 8-bit null terminated

    // File handle
    typedef int FHANDLE;

    // File system routine status
    typedef int FSTATUS;

    // Haven't used C in a while so if const keyword is supported then use it

    FSTATUS OpenFile(FHANDLE* fileHandle, char* filePath, unsigned int flags);
    FSTATUS CloseFile(FHANDLE fileHandle);
    FSTATUS ReadFile(FHANDLE fileHandle, char* arrayForReading, unsigned int sizeToRead, unsigned int* numberOfBytesRead);
    FSTATUS GetFilePointer(FHANDLE fileHandle, unsigned int* currentPointer)
    FSTATUS SetFilePointer(FHANDLE fileHandle, unsigned int newPointer);
    FSTATUS WriteFile(FHANDLE fileHandle, char* arrayForWriting, unsigned int bytesToWrite, unsigned int* bytesWritten);

     
    You then take this interface and implement the actual code somewhere else.
     
  11. May 8, 2012 #10

    rcgldr

    User Avatar
    Homework Helper

    Removing or inserting sentences, just requires the ability to allow the user to specify a sentence to delete and being able to enter a new sentence to insert.

    Modifying a sentence requires a user interface that allows the user to move a cursor back and forth, and modify, insert, or delete characters, while maintaining the current display of that sentence on the user's screen as well as in the program's memory. I find it difficult to believe that this is what the instructor intends for you to implement.

    If this is allowed, you could implement a "modify" that just deletes a sentence and requires the user to enter a new sentance to replace the one that was deleted. You should find out from your instructor if this is acceptable.
     
  12. May 8, 2012 #11
    modifying was indeed too difficult for amateur like me. i am exposed to C just 11 weeks ago. anyway thanks for the help you both gave. it is really helpful
     
  13. May 9, 2012 #12
    one last question. how to add a word into a string and how to remove a word from a string? ps: not replacing word
     
  14. May 10, 2012 #13

    chiro

    User Avatar
    Science Advisor

    The short answer is to allocate memory big enough for the two strings (string1size + string2size + 1 for null terminator character assuming ANSI 8-bit string), and then copy the contents from string1 into array then string2 into array and then set last byte to 0x00.

    If you are adding a word in-between then do the same thing as above but instead of two strings you will have three strings and you add them all together. If you are removing something from a string, again do the same thing: allocate memory for a new string, copy of the contents that don't include the stuff you are removing (string1 = string before stuff being removed, string2 = string after stuff being removed) and then put the null terminator at the end.

    Also remember to clean up any memory that needs to be deallocated and check for errors throughout the entire process and clean up any loose ends accordingly. Also make sure that the memory is allocated correctly: (check if pointer is non-zero).
     
  15. May 10, 2012 #14
    I have started to code in Pascal then C since I was 18, and changed myself abruptly into C++ because C made me suffer a lot; its constructs always induce leaks. That means it is wet and therefore easily contaminated with security holes and viruses. For your references, you can resolve your current problem with a linked-list in which you can store your words as nodes; Therefore, adding and removing a node also means adding and removing a word.
    Code (Text):

    struct WORD
    {
       char myword[999];
       WORD*newWord;
       //etc
    };
     
  16. May 10, 2012 #15
    okay... how should i initialize each string[] as the text can be randomly input by the user?
     
  17. May 10, 2012 #16

    rcgldr

    User Avatar
    Homework Helper

    You could split up the process into one where you use 2 or 3 strings as mentioned by chiro, or you could directly insert or remove words from an existing string by shifting all the characters after the word, downwards if deleting a word or upwards if inserting a word in the array. If shifting upwards (inserting), you would have to start at what will be the end of the updated string to avoid overwriting existing characters. In both cases, you move one character at a time.

    I'm not sure this buys you much. With a linked list, you have to parse the original input sentence string into a linked list of words, and you have to traverse the linked list to create a sentence string for output. It does make inserting and deleting words easier. If you want to try this, you just initialize each string to a nulll string. Also it would make more sense for the name of the node pointer in the word structure to be "nextWord", instead of "newWord".
     
  18. May 10, 2012 #17
    what's the code for this? anyone?: add spaces between words in spaceless C string
     
  19. May 10, 2012 #18

    Mark44

    Staff: Mentor

    As already noted in this thread, we are not here to do your work for you. You've been in the class now for 11 weeks, so you should have some idea how to write C code. Show us what you've done and we can help you with it, but don't expect us to do the work for you.
     
  20. May 10, 2012 #19

    Mark44

    Staff: Mentor

    How is C++ different from C in that regard? If you forget to free() a pointer to heap memory in C or you forget to delete memory that you allocated with new, the result is the same - a memory leak.
    wet - ???
    Memory leaks are not security holes, and are not an avenue for viruses.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How to write a C programming proposal?
  1. Writing a program in C (Replies: 8)

Loading...