So I have to write a code for my C++ class, and I am having a problem trying to figure out how to get my code to read multiple int values. This is what my code should look like
Enter two times in military format (e.g., 1730 1520): 1730 1520 [1520<1730] Enter two times in military format (e.g., 1730 1520): 1520 1730 [1520<1730] Enter two times in military format (e.g., 1730 1520): 1730 1730 [1730==1730] Enter two times in military format (e.g., 1730 1520): 1760 1520 1760: [INVALID TIME 1] Enter two times in military format (e.g., 1730 1520): twelve 2 [INVALID NUMERIC INPUT]
at the moment my program is extracting keyboard data through accessing the virtual key states. However, it is not performing as I intended because the data I receive from the console does not concur with the actions the user performed.
E.G. When I type, it comes out like this.
what I get with my program: WWhhhheeen III typeeee, iiit ccoommes oout lllikkke thhhhiiis
TLDR: so basically Id like to know how other programs know how to interpret keyboard input, so that when I type I dont get multiple inputs of the same key press
This program gets input from a file and output to the screen and to a file. The difficulty I am having is summing the number I retrieve from the file for the individual numbers of sightings.
#include <fstream> // enables us to read and write files #include <iostream> // for cin and cout #include <cstdlib> #include <string> // enables us to hold strings of characters #include <cctype> using namespace std;
I am in the process of writing a program that will give the appropriate color code for a resistor after the user enters an integer value for the resistance needed and selects the tolerance form a list. My question is this: Is there a way to allow the user to enter a value such as 75000 and C++ use each digit separately, as if they entered 7 [enter], 5[enter], 0 [eneter]... and so on? But, then use the entire value as an integer too? Also, it should read a value such as: 45835, as 45000, or 1843 as 1800.
I`ve wrote a function for my utility to XOR char* buffer by a key, then to reverse it with the same key. Here is the code, it`s simple enough:
Code:
static inline char* XOR_buffer(const char* d, const char* k ) { char *newstr = (char*) malloc(sizeof(char)* strlen(d)); newstr[0]=''; printf("%d is size of string ", strlen(d)); char *begin = newstr; char* ret = begin; int len = strlen(k); }
[code]....
The lengh of the string is reduced by the second XOR call. You can try it out, just define XORDBG to view the error message in the second pass to the buffer.
i created an com client that try to create com server with the command CreateInstance. at win 7 it works fine (both 32 and 64 bit). but with xp it fails. i created the app with win 7 - 64 bit.
When I ran it only the calls from doers array is called 7 times normally, and donters only one time. Why is that? When I call doers from the second loop, it prints the doers functions again....and only one call to donters is made to the first static inline donter functions __dont1()...
What I have is a main function that takes input characters from the command prompt during the main function call, and coverts it to an integer array a using atoi. (starting at the 2nd character - the 1st is reserved for another call that I plan to reference later, and the 0th is obviously the ./function). A function is then called to find the mode of an array (the range of values in the array is 1-30). Now, when I run the whole thing, I get a segmentation fault (core dumped) for even number of arguments. It's late and I've been staring at it for too long...
Code: #include <stdio.h> #include <stdlib.h> int get_mode(int a[], int count);
I'm trying to write a piece of code that calculates the difference in days between two manually input dates. The part of my code that's causing problems is:
xxx
When running the code and prompted to enter the date, if I input for example 31/12/2014, it'll be rejected and send me back to the beginning of the loop. Any date with 31 days involving months 1, 3, 5, 7, 8, 10 or 12 causes this problem. All other valid dates however work perfectly fine (e.g. 30/4/2014).
Something possibly worth mentioning is that, when I take out all other conditions from the loop, i.e.
xxx
it works fine (31/12/2014 is accepted), but of course I need all of the other conditions in there too.
I have a quick question about dynamic memory. I know that if you are dynamically allocating memory for a single data array and it fails, you can immediately abort the program via a return statement, but is this also true with multiple data arrays? For instance:
int *foo, *bar foo = new (nothrow) int [5]; bar = new (nothrow) int [5]; if (foo == nullptr || bar == nullptr) return -1; else /*rest of execution */
If the answer to the previous question is no, do you need to do a delete[] on the arrays that succeeded before terminating the application? Say foo is correctly allocated but bar fails, would you have to do something like this?
int *foo, *bar foo = new (nothrow) int [5]; bar = new (nothrow) int [5]; if (foo == nullptr || bar == nullptr) { if (foo == nullptr && bar != nullptr) delete[] bar;
I'm trying to write a wrapper for rapidXML in order to use it in my projects however I've run into a curious bug that's preventing me from properly saving the XML documents I'm working with. The gist of it is: simply parsing a very simple xml doc and then saving the same document to the same file (without modifying it) creates a mostly correct output except for scrambling a few node closures:
As a foot note: I'm almost certain it's not an issue with the parse() function.
If I parse() the document and then call std::cout<<doc; it prints the document perfectly fine to the console, but for some reason std::ofstream<<doc; causes issues.
I'm getting a "passing...discards qualifiers" error on my if statement and not sure why because I'm not changing anything. I know removing const or making test mutable fixes the issue. I've been taught to always make a function const if it doesn't change anything, in which case, have I finally come across an acceptable time to use mutable?
The code is supposed to display the total and averages of the data as well, but cuts off due to an error in the code. The code should also:
1)Print checks for all employees, one per page, sorted by lastname. The first check number, 100, is to be read from a company data file (see requirement 4). The border of each check is important and should not be omitted.
2)Convert the net pay to a text string for each check printed.
3)Print a reference code on each check. The reference code is obtained by combining the first letter of the lastname with all the consonants remaining after removing all vowels (a,e,i,o,u).
4)Use the same employee data found in assignment 2. Use the following company data, obtained from a text file,
Output I'm expecting: Program to display totals and averages (worked before I turned everything into an array), now exits with error before totals/averages are displayed. Program also writes up a report.txt file that also writes this information into it, as well as using a quicksort to organize the names alphabetically, and print paychecks (all of the #BORDER, #HEADER1-8, #STUB, etc). In that check a reference code is also generated (teacher gave us code, we just had to modify for our final program as seen here)
Flow of the program: Print headings to label all of the input data we will enter soon under the categories as listed in the heading. Initialize all of our totals (in our array) to value of 0. These will be added in a loop "AddAccumulators" which takes our value for the hours, payrate, and taxes from each employee array structure and adds it to the total array. Program will write this information into the report.txt file with the HEADER line for totals, and should be displaying it in that picture. (Same for averages). After all of the data is calculated, the Reference code, Totals, Averages, and individual employee data is taken and put into printing out a Check Header and Stub.
This compiler on SYSTEM2 is happy. but second way does not look correct to me and compiler on system 1 complains about it. Which is the correct way to allocate memory?
If first one is correct then what should i look in for to avoid this error? Could this be an issue with compiler on SYSTEM2? If i use second method on SYSTEM2 code segfaults during malloc.
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct mystruct1 { int a; int b;
Background: I'm using SDL and CodeBlocks and trying to make a Graphics class that would simplify some SDL operations such as drawing and loading images.
Issue: The loadImage function in the graphics class fails to load the image correctly and so the program prints out a blank window during run-time. I've tried multiple ways of passing a string literal into the function the surface temp fails to load and so background in Game fails to load. After testing it several times, I'm pretty sure that the issue lies with SDL_LoadBMP not registering the passed variable for whatever reason. I know the image is in the right place as writing SDL_LoadBMP("./Graphics/image.bmp"); brings it up just fine.
Current Code:
Main simply creates a Game object and execute(), so I didn't feel the need to put it on here.
Output: A blank window. (It should show the background image but doesn't.)
Note: I originally wrote it as gfx.loadImage(background, "./Graphics/image.bmp") but that gives me a conversion warning and still fails to show the image when the program runs. I've tried looking up examples similar to what I was doing but no one else seems to have this problem.
I am getting some weird errors while building in release mode. It works fine in debug mode. Libraries and includes are linked in both debug and release version, but it's acting like it's not.