How to get started? Simple text editor with C - c

I have to do a simple text editor using the c language. But I don't know how to get started. The program should begin with a blank screen, waiting for the user to write something. The user is also able to move the cursor using the arrow keys and the user is also able to load text files to the program from his hard drive and also make a text file of something the user has written in the program.
He can load something by pressing CTRL-O or he can press CTRL-S to save something followed by the name of the text file.
Our professor said that we have to use the library screenUtils to make the cursor move.
How should I start? I'm trying to make this work for 3 hours but nothing really works.

Our professor said that we have to use the library screenUtils to make the cursor move. How should I start?
I would start by reading the documentation for this library.

Related

Delete current terminal input line

I am trying to code a little console chat-program in C on linux.
So far I coded it in a way that both chatting partners are only able to alternately send/recv, because these function calls are blocking by default.
Now I would like to modify that program, so that both are able to send and receive simultaneously.
The problem that I find is, that once you typed some input to the terminal, I don't know how to output received messages, without messing up the current input line of the terminal.
If there was a way to delete that current input line, you could temporarily save that line, print the new message and put the input line right back.
However, I was not able to find a solution for this problem on the internet.
Is it possible to delete the current input line, and if not, how else could I achieve what I want?
I think you should look into ncurses as Edd said in his comment.
It would allow you to easily manage contents in your terminal window, which sounds like a good idea for your chat program.
All you'd need to do is store your messages in 2 character arrays:
char incoming[MSG_MAX]
and
char outgoing[MSG_MAX]
Then you can output those messages wherever you want in your terminal window, since ncurses allows you to specify x,y coordinates on where to put your text.
Then a simple wrapper for one of ncurses erase() family functions would allow you to delete characters from specify x,y coordinates in your terminal window.
Edit: MSG_MAX is not an actual ncurses macro.

Resizing output Terminal in C Language

would like to get some help on a c project i am currently working on. I have a string/array of output to the terminal, but somehow the standard terminal is too small for my output. Even after i manually expand the window of the console the output is still cut off, instead of printing in a single line, it just gets cut off and go to the next row automatically.
hope to get help.
I think that the only way to correct this is by splitting your one-line output in multiple lines, using "\n" at the end of every line.
By doing this you can control when and where it has to write in the next line, and you can make it look more like you wanted to.

IRC(Twitch chat) Text-to-speech

Hey everyone I'm looking for a way to code a program/bot in VB that would read my chat, but only if a command is used
For example: "!tts Hello"
And It would read it using TTS and show it on screen
$USERNAME$ !tts: Hello
Now the thing I don't know how to set up is the program reading the chat, printing it on screen I believe is the easy part.
Also if it's possible to add an option to select to which audio output it will go.
You need to study more coding...
Im not a master at it myself. but i would make a boolean that could be true if the first letter in a chatline is a "!". And then a command that would add that line to a text-to-speech module

How can I get use input to create a file within a program

I am currently using a software dev. tool kit for a camera. I am able to take a pictur with this camera and save it as a bmp, but I have to hard-code the file name within the script.
The camera uses the file name I now hard code as an element for a structure that it uses as an argument for its save function.
Example:
imageparam.filename = L"hardcodefilename.bmp";
I would like a user to be able to type a file name, and have that name inserted into the above example. I am having a hard time getting around the quotes that are used in the code. Is there any way to use getline() or scanf() and have its input feed in between those quotes?
Note: I've only been using C for a few weeks, so please be kind if the solution is obvious.
I find the easiest way is to pass as arguments to the main function. So in Visual Studio, you just pass as command line arguments. In that fashion, you always can give the user control to save a file name.

Unable to put a simulation in C to a webpage

I have the following simulation in C for cars in a traffic circle
alt text http://dl.getdropbox.com/u/175564/cars.png
For example,
7 <space> <enter>
gives more cars to the simulation, while
s1 <enter>
puts a top sign to the incoming road #1.
I want to put the simulation to an internet page such that users can try it.
However, I do not know where I should start.
I know Joomla and little about Django. Perhaps, they can be useful.
How can you put a C program to a Webpage such that users can use it?
CGI is what you want; it will let you embed any program you want into a website, it was made for that purpose. Then perhaps embedding a few more options with PHP and HTML will let the user acutally input data into the program via the web. It should not be too hard.
Take a look here for more info: http://www.cs.tut.fi/~jkorpela/perl/cgi.html
I think that is a good pointer in the right direction. I hope that helps.
You could run the C code in a flash app using alchemy:
http://labs.adobe.com/technologies/alchemy/
Here's a good intro to writing CGIs in C: http://www.cs.tut.fi/~jkorpela/forms/cgic.html
However, since you're a beginner, I'd recommend porting your program to PHP. It's a very easy language to pick up, and it's a much easier route than writing a CGI in C.
I assume the C program needs input while it's running and not via command-line arguments? If I'm wrong, you can just use PHP and shell_exec() to run the program. The function returns anything printed to stdout.
Such a page might look like:
$sim = shell_exec("/path/to/binary -a 5 -b 6");
echo $sim;
Where the string passed to shell_exec is exactly what you'd type on the command line.
If you want a dynamic simulation, where the cars moves while you watch , you'll need an applet or flash.
A cgi program renders the page on each http GET/POST (on reload, submit etc)
and that is probably not what you want.
I would start with a flash or java applet wrapper. You can communicate with your application over a tcp connection and display the results in the flash or applet.
I would recommend going with sockets. If your C program could set up and listen on a local or internet socket, you could use the socket facilities in any language to send it arguments and get output.
If that's going to be too much of a pain, have php exec the program while directing the output to some file. Then, have php read that file.
Looking at the output of your program, I think trying to print the results of shell_exec() will result in clobbered output.
So, you could shell_exec("/bin/program -arguments > /tmp/prog-tmp.txt") , then read prog-tmp.txt.

Resources