How to write a C programming proposal?

Click For Summary

Discussion Overview

The discussion revolves around writing a proposal for a C programming project titled "Word Processing." Participants explore the requirements for creating a basic word processing interface that allows users to input, modify, add, and remove text, as well as save it in "txt" format. The conversation includes algorithm development, interface design, and coding challenges.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in developing an algorithm for the proposed word processing interface.
  • Another participant emphasizes the importance of defining the interface, including functions and data structures, before coding.
  • Some participants clarify the difference between modifying, adding, and removing sentences, noting that modifying may require a more complex user interface.
  • A participant suggests that modifying sentences could involve replacing them rather than editing them directly, questioning the instructor's expectations.
  • There is a request for examples of interfaces, leading to a shared example related to file I/O.
  • One participant shares a method for adding and removing words from strings, detailing memory allocation and string manipulation techniques.
  • A later reply introduces the idea of using a linked list to manage words as nodes, suggesting a potential solution for the project.

Areas of Agreement / Disagreement

Participants generally agree on the need for a clear interface and the distinction between different operations on text. However, there is no consensus on the specific implementation details or the complexity of modifying sentences, leading to varying interpretations of the project requirements.

Contextual Notes

Some participants express uncertainty about the instructor's expectations regarding the complexity of the user interface for modifying sentences. There are also discussions about memory management and error handling in C programming, which may not be fully resolved.

Who May Find This Useful

Students learning C programming, particularly those working on projects involving text manipulation and interface design, may find this discussion beneficial.

yukari1310
Messages
16
Reaction score
0
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.
 
Technology news on Phys.org
yukari1310 said:
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.

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.
 
I need the solution asap cause i have to submit the proposal by this friday... can anyone out there help me?
 
yukari1310 said:
I need the solution asap cause i have to submit the proposal by this friday... can anyone out there help me?

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.
 
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, ...).
 
Yes. It is the code that i need. What's the different between removing/inserting and modifying? they sound the same to me
 
yukari1310 said:
Yes. It is the code that i need. What's the different between removing/inserting and modifying? they sound the same to me

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 occurred.

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.
 
Can you show me an example of interface?
 
yukari1310 said:
Can you show me an example of interface?

Here is a really simple one for a file system:

Code:
// 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.
 
  • #10
yukari1310 said:
Yes. It is the code that i need. What's the different between removing/inserting and modifying? they sound the same to me
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.
 
  • #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
 
  • #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
 
  • #13
yukari1310 said:
one last question. how to add a word into a string and how to remove a word from a string? ps: not replacing word

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).
 
  • #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:
struct WORD
{
   char myword[999];
   WORD*newWord;
   //etc
};
 
  • #15
okay... how should i initialize each string[] as the text can be randomly input by the user?
 
  • #16
yukari1310 said:
one last question. how to add a word into a string and how to remove a word from a string? ps: not replacing word
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.

phylotree said:
For your references, you can resolve your current problem with a linked-list in which you can store your words as nodes.

yukari1310 said:
okay... how should i initialize each string[] as the text can be randomly input by the user?
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".
 
  • #17
what's the code for this? anyone?: add spaces between words in spaceless C string
 
  • #18
yukari1310 said:
what's the code for this? anyone?: add spaces between words in spaceless C string
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.
 
  • #19
phylotree said:
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.
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.
phylotree said:
That means it is wet
wet - ?
phylotree said:
and therefore easily contaminated with security holes and viruses.
Memory leaks are not security holes, and are not an avenue for viruses.
phylotree said:
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:
struct WORD
{
   char myword[999];
   WORD*newWord;
   //etc
};
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
2K
Replies
69
Views
11K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
35K
  • · Replies 25 ·
Replies
25
Views
3K
Replies
81
Views
8K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
Replies
4
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K