C :: Possible To Instantly React To Keystrokes Made In Console?
May 3, 2014
Is it possible in C to instantly react to keystrokes made in console?For example, consider the following code:
Code:
#include<stdio.h>
int main(int argc, char *argv[]) {
char ch;
printf("Enter a sentence...
");
[code]....
The evaluation of the if statement inside the loop will not occur until the Enter key is pressed on keyboard.To my best understanding, It just pushes the keystrokes to some buffer, and when the '' is introduced, it evalutes the characters one by one.Is there an elegant way to instantly react to keystrokes in C?
View 5 Replies
ADVERTISEMENT
Aug 13, 2014
I compiled/built a code I had and made an executed file but when i click on it the CMD closes instantly. Is there anyway to keep this open?
View 10 Replies
View Related
May 23, 2013
Here's my code, my problem is that it is not sending the keystrokes to the LOG.TXT file I want them to be going to.
1 #include <iostream>
2 using namespace std;
3 #include <windows.h>
4 #include <winuser.h>
5 #include <stdio.h>
6 int save (int key_stroke, char *file);
[Code] ....
View 1 Replies
View Related
Sep 15, 2014
So I'm trying to send 2 keystrokes to a certain program. Let's say I would like to send the keystroke "1" twice, to notepad.
View 7 Replies
View Related
Oct 28, 2014
So I have been assigned a program that counts keystrokes, alphabetical characters, and vowels. I have the program working as desired but I just can't figure out how to make it end upon ONLY the "return" key being pressed.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ( void ) {
[Code] .....
View 7 Replies
View Related
Apr 18, 2014
If I create a file that looks like this for example,
car 2 4 6 8
truck 1 2 3 4 5 6
plane 4 5 6 7 9
Whenever I go to open it back up like this,
ifstream inputFile;
string line;
inputFile.open("file.txt");
while (inputFile>>line) {
cout << line << endl;
} inputFile.close();
return 0;
}
It displays output like this,
car
2
4
6
8
How can I get it to display like above?
View 2 Replies
View Related
Mar 7, 2013
You are given an integer, perhaps a very long long integer, composed of only the digits 1 and/or 2. You have the ability to change a 1 digit into a 2 and a 2 digit into a 1 and must determine the min. number of changes that you can make resulting in no 2 digits remaining in the number that are in a position(in terms of powers of ten) higher than any 1 digit.
example:
2222212 number of changes:1
1111121 1
2211221 3
1122112 2
no negative numbers.
how to get started. Also I'm not allowed to use anything related to arrays or sorting.
View 6 Replies
View Related
Oct 2, 2013
I want to monitor a text file. So far what I have is the program reads and prints the names in the file to standard out. When the program reaches the end of the file, it closes.
I want the program to stay active and continue to print names as they are saved to the text file.
I was toying with FindFirstChangeNotification function, but it seems that returns a handle so I'm back to the drawing board.
View 1 Replies
View Related
Feb 13, 2014
I want to make an encapsulated surface class that keeps track of important aspects about a surface. I have it started, except when I test the .onDraw() function, nothing appears on the screen. My Code is below:
#include "NSurface.h"
NSurface::NSurface() {
surface = NULL;
}
NSurface::~NSurface() {
SDL_FreeSurface(surface);
[code]....
why nothing is blitting to the screen when I test that class.onDraw() and SDL_Flip(screen)?
View 1 Replies
View Related
Feb 8, 2015
I want to know how to respond to a request made by a mobile application (preferably Android) through a desktop software. So for example if there is a button on the mobile app named 'do something and a user clicks it, I want the desktop software to respond to that request and 'do something
So what I was thinking was to upload a file to a server when the button on the app is clicked and add a timer to the desktop software to connect to the server and read the file and respond accordingly.
Is this how it is usually done or am I going about this the wrong way? Im developing the app in C# (Xamarin) and the desktop software in C# as well.
View 6 Replies
View Related
Nov 25, 2012
Running c in jgrasp.. i am getting error has gcc not found.
View 4 Replies
View Related
May 8, 2015
implementing a game of chess, i was able to easily implement the grid with an 8x8 multidimensional array.but here is the case I need to implement a grid made of hexagons(six sided but in future may be seven sideded or eight may be needed): like a beehive something.
How can such a grid be implemented in c++ taking notes of coordinates and borders and stuff? From where i can start working from? this grid has to be just like the chess grid only we got six sided boxexs instead of four,
View 6 Replies
View Related
Jan 6, 2015
I am supposed to convert a string made of many numbers between every number spaces are between, to an integer variable for every number..
How am I supposed to get over this problem?
Example: String: " 322 52 231"
View 1 Replies
View Related
Jun 19, 2014
I dont know anything about filestreams. I want to record the files that the customer bought, total, cash and change.
Here's my code.
// Create a program that will initiate a purchasing system for registered agents in an agency.
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
void password();
[code]....
View 1 Replies
View Related
Apr 25, 2013
I am doing a c project .it is a system that stores the name of txt format reports made by students and opens them.
View 1 Replies
View Related
Sep 30, 2014
I have a client/server program. My Client process spawns my server process using a `fork()` and `system()` call. The client and the server are meant to communicate to each other through named piped, that is a requirement of my homework. The client and the server are supposed to initially send a message to the other one, through a pipe, to confirm that a connection is made. My issue is that my client is trying to open one of the named pipes before the server has a chance to make it. This doesn't always happen though. Occasionally, it will run fine. Is there some way to synchronize this?
My overall goal is to get a filename and search target from the user, send those to the server through a named pipe. And the server searches for the target and sends info back.
OUTPUT:
Client: PID 2986 - Running on Tue Sep 30 20:59:28 2014
Client: PID 2986 - Enter File Name: largeSampleText.txt
Server PID 2988 - Running on Tue Sep 30 20:59:32 2014
Server: PID 2988 - Synchronized to Client.//This means the client-to-server fifo is working
There was an error opening serverToClientfifo//This means client couldn't open the server-to-client fifo
error is: 2//This means the fifo doesn't exist yet
[Code] ....
CORRECT OUTPUT:
Client: PID 2542 - Running on Tue Sep 30 20:58:44 2014
Client: PID 2542 - Enter File Name: largeSampleText.txt
Server PID 2557 - Running on Tue Sep 30 20:58:54 2014
Server: PID 2557 - Synchronized to Client.
[Code] ....
RELEVANT CLIENT CODE:
int main() {
char requestedFileName[1024];
//Get initial information on the client
pid_t clientPID = getpid();
time_t currentTime = time(0);
char* stringTime= ctime(¤tTime);
[Code] ....
I tried creating both of my fifos in my client and my output changed to this
Client: PID 3150 - Running on Tue Sep 30 21:23:17 2014
Client: PID 3150 - Enter File Name: largeSampleText.txt
Client: PID 3150 - Enter Target:
Server PID 3153 - Running on Tue Sep 30 21:23:21 2014
was
Client: PID 3150 - Input File >>>largeSampleText.txt<<<
Client: PID 3150 - Target >>>was<<<
Client: PID 3150 - Synchronized to Server
Server received unexpected connection message
Message: was
Terminating
So It appears like the client went ahead and put `requestedFileName` and`requestedTarget`into the pipe and the server read out `requestedTarget` instead of the connection message. Not sure why though
View 1 Replies
View Related
Jul 9, 2014
I was going through Singleton design pattern and get to know that objects can be created only by static function of that class and constructors are make private.
My question is, why assignment operators are not made private through which we can create a copy of already existing object.
I tried below code and assignment works, so I have new object sc3. I know that its referring to memory of sc1 but finally I was able to create object without using static function.
Also, why copy constructor not made as private.
Below is code:
#include <iostream>
using namespace std;
class Singleton {
private:
static bool instanceFlag;
[Code] .....
View 3 Replies
View Related
Feb 20, 2013
Write a C program that calculates the final value of an investment made in a TSX Market Linked GIC.
Specification
The return on this type of GIC (Guaranteed Investment Certificate) is based on the initial investment, the number of years (1, 2 or 3), a minimum return rate, a maximum return rate, a participation rate, the values of the TSX (Toronto Stock Exchange) index at specified intervals during the years, and the type of averaging of these values. The final investment value can only be calculated once all the TSX values are known.
If averaging is not used the TSX rate is determined from the opening and closing values only. If averaging is used the TSX rate is determined by calculating the TSX average at 6 monthly intervals, then is based on this average relative to the opening value. The TSX rate is then multiplied by the participation rate. If this new rate is below the minimum rate, then the minimum rate is used, and if it is above the maximum rate, then the maximum rate is used. Rates are printed to 2 decimal places, and the final investment is rounded down, and formatted using commas.
Only round down for the final investment. If the TSX rate is negative do not print the line for rate adjusted for participation. Assume that the final investment is less than one million dollars. (Hint: if you need to print leading zeros in a number, use the %0m.n format: example - the format specifier %06.2f prints 4.56 as 004.56)
Example 1: See below; averaging is not used, so TSX rate = (107-100)/100 = 7%. After using a participation rate of 80%, get 5.6% (which is between min & max rates).
Example 2: See below; averaging is used over 5 values to get a rate of 68% which equals 54.4% due to participation. This is more than the max rate, so the max rate is used.
The GIC calculator must use the following layout exactly.
+------------------------------------+
| TSX MARKET LINKED GIC CALCULATOR |
+------------------------------------+
Enter initial investment : 1000.00
Enter number of years [1,2,3] : 3
Enter minimum and maximum rates [%] : 1 20
Enter participation rate [%] : 80
Enter if averaging used [1=yes,0=no]: 0
Enter open and close values : 100 107
TSX rate . . . . . . . . . . . . . . 7.00%
Rate adjusted for participation . . 5.60%
Final investment . . . . . . . . . . $ 1,056.00
+------------------------------------+
| TSX MARKET LINKED GIC CALCULATOR |
+------------------------------------+
Enter initial investment : 2000.00
Enter number of years [1,2,3] : 2
Enter minimum and maximum rates [%] : 1 20
Enter participation rate [%] : 80
Enter if averaging used [1=yes,0=no]: 1
Enter 5 TSX values : 200 190 320 430 540
TSX rate . . . . . . . . . . . . . . 68.00%
Rate adjusted for participation . . 54.40%
Maximum rate is applicable . . . . . 20.00%
Final investment . . . . . . . . . . $ 2,040.00 i wrote something like
Code:
#include <stdio.h>
int main (void)
{
int years, minimum, maximum, partrate, x, open, close, tsxvalue;
float investment, tsxrate, y, finalinvestment, maxrate, minrate;
printf("+------------------------------------+
[Code] ....
I don't know what the exact calculation should be here now to get the rest....so I'm stuck here
View 2 Replies
View Related
Mar 4, 2012
Code:
class A
{
std::map<std::string, Unit*> aMap;
class B
[Code] .....
This code snippet results in "A non-static member reference must be made relative to a specific object". When I make callA() static, this error goes away, but there is problem with aMap.
View 2 Replies
View Related
Oct 11, 2014
Main console: qwer.exe
Secondary console: asdf.exe
System(c:asdf.exe);
I wanna open this asdf.exe new console. Not in the qwer.exe.
View 1 Replies
View Related
Dec 22, 2014
Im having a problem with the below code within a console app, I am copying and pasting data across server locations, the copy works fine but it looks like the app wont close and I am left with the screen (Shown in attachment). I want to run this in part of a batch process but because the app stay open it wont move onto the next task.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace SQL_Backup_Move_Files {
[Code] ....
View 3 Replies
View Related
Jun 29, 2014
So I'm making a console rpg and after the task of making my save/load functions I began making a sha-256 checksum so the save file can't be edited. I've pretty much all of the code but when I save the game and the checksum of that save file with my save function, I go back to load it and it always goes to the statement that says the checksums do not match and when I check the chksum.dat the hash is the same every time, here is my code:
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "sha256.h"
using namespace std;
void MaximizeWindow() {
[Code] .....
View 3 Replies
View Related
Jan 28, 2014
I want to show and control mouse in Win32 Console. What should I do? And I want to learn MFC programing.
View 3 Replies
View Related
Apr 6, 2013
Any tutorials on adding a UI to a console application? All I really need is a button that will run one function every time I click it.
View 1 Replies
View Related
Apr 4, 2013
I have 18,000 lines of code that i would like to upgrade to include a log file. I want to replace the cout with a stream or something similar so that i can easily output to the console and to a log file at the same time with minimal change to 18,000 lines of code. I'm nearly there.
I used this post heavily as a reference; [URL] .... however it is highly incomplete and this is above my knowledge so I'm struggling somewhat.
I was able to get the bulk of it working with some guess work and modification to the code from that link.
For some reason i had to comment out "mstream(void);" and "~mstream(void);"
Also how to get :
mstream& operator<< (ostream& (*pfun)(ostream&)) {
pfun(coss);
pfun(cout);
return *this;
}
to work for endl as per the previous link. Not sure if i'm even putting it in the right place. Otherwise the code works fine for streaming to both locations and such. See the code below;
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class mstream {
[Code] ....
View 9 Replies
View Related
Aug 5, 2013
I have created a game that functions correctly, however, for balancing and future changes, I would like to record results .txt document (its 1v1 btw). I already have code to determine who won and what I am looking for is some way to keep track of different match-ups for the different characters. Im looking for something like this:
loser
Winner char1 char2 char3
char1 3 2 5
char2 2 5 4
char3 8 1 2
the numbers are the amounts of wins a given character has over another character. I'm looking for code to open the .txt file and add 1 to the respective win total so I can do balance changes and such.
View 1 Replies
View Related