C :: Implementing Custom Behaviour But Something Fails
Jan 2, 2015
I am creating a special struct with unknown functions. I use this approach:
Callbacks.h Code: #ifndef CALLBACKS
#define CALLBACKS
struct Callbacks;
struct Callbacks* getNewCallback();
[Code]....
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()...
View 7 Replies
ADVERTISEMENT
May 24, 2013
I've been pondering which of these 2 approaches would make for the best interface for a library: Defining custom exceptions with specific names for different error scenarios but with standard behaviour, or simply using the predefined exceptions from the STL.
This is my current approach:
Code:
namespace rpp
{
class ConnectionError : public std::exception
{
public:
ConnectionError(const std::string &p_err);
[Code] .....
This seems to make for more descriptive code but it adds no functionality and the implementations are completely identical, which seems "off" to me, somehow.
View 8 Replies
View Related
Jul 8, 2012
is there a way to have a template class respond to missing stuff in a template type ?
Code:
template <typename Type>
class MyClass
{
public:
enum { ID = Type::ID }; // revert to 1 if Type::ID doesn't exist.
};
If the Type passed to the template has an ID member (required to be an enum or a static const int), use it, if it is missing revert to a default value.
I can use this as a simplified way of configuring how MyClass works, without requiring Type to explicitely needing to define what it doesn't care about.
It needs to be resolved at compiletime, as it determines the number of elements in member array variables.
View 10 Replies
View Related
Jan 12, 2015
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.
View 9 Replies
View Related
May 29, 2013
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.
View 14 Replies
View Related
Oct 6, 2014
cin returns fail on trying to read double value.
Code:
#include<iostream>
#include<array>
using namespace std;
const int MAX = 10;
void read_donations(array<double, MAX>& a, int& count);
int main()
[Code] ....
View 4 Replies
View Related
Nov 3, 2013
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);
[Code]......
View 1 Replies
View Related
Mar 29, 2014
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.
View 1 Replies
View Related
Apr 13, 2014
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;
[Code] .....
View 4 Replies
View Related
Jan 25, 2015
So the question is this [URL] .....
My code is this:
#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, char *argv[]) {
long double div;
//div=((1e+9)+7);
[Code] .....
The problem is when the hackerrank inputs the following:
10
5351871996120528
2248813659738258
2494359640703601
6044763399160734
3271269997212342
4276346434761561
2372239019637533
5624204919070546
9493965694520825
8629828692375133
My code gives the wrong output.
The output is supposed to be
578351320
404664464
20752136
999516029
743537718
323730244
174995256
593331567
136582381
305527433
So what changes should I make to get my code give the correct output.
View 9 Replies
View Related
Feb 4, 2015
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:
bool rXMLwrapper::parse(){
try{
std::ifstream file(filepath.c_str());
if(!file.is_open()){throw std::bad_alloc();}
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
[code]....
I'm using this patch for rapidXML: [URL]
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.
View 1 Replies
View Related
Jan 27, 2012
Why I'm getting an error here. I've dumbed down my code for simplicity and removed irrelevant code.
PHP Code:
class Foo {
public:
bool IsNull() const;
private:
std::map<int, int*> test;
[Code] ....
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?
View 9 Replies
View Related
May 17, 2014
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,
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
[code]....
And here's where the program stops. URL.....
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.
View 10 Replies
View Related
Dec 9, 2013
How do i display the output ? This program only saves the output to "gpa.txt" I want it to also display the output to cmd.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
const int SIZE = 10;
[Code] ....
View 1 Replies
View Related
Jun 23, 2014
I have this proxy class generated from a webservice:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="java:se.atg.aisbean.calendar")]
public partial class RaceDayCalendarSimple : object, System.ComponentModel.INotifyPropertyChanged {
[Code] ....
I'm trying to access this method "RaceDaySimple[] raceDay" and display it on "WebForm1.aspx":
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebServiceClient.WebForm1" %>
<!DOCTYPE html>
[Code] ....
So on "WebForm1.aspx.cs" I'm trying to access the method "RaceDaySimple[] raceDay" and display it inside the div "test":
test.InnerHtml = pbs.fetchRaceDayCalendarSimple().raceDay;
But I'm getting the error:
Cannot implicitly convert 'WebServiceClient.InformationServiceReference.RaceDaySimple[]' to 'String'
So how do I acces this method proparly and display the content on "WebForm1.aspx" inside the div "test"?
View 1 Replies
View Related
Dec 27, 2012
I have some problem while allocating memory to a union inside structure. Below is the code i am using
ON SYSTEM1:
This works fine
ON SYSTEM2:
compiler complains saying "need structure or union type" while allocating MYSTRUCT1.
If I change:
shreyas[0].UnionAttr.struct1 = (MYSTRUCT1 *) malloc (sizeof(MYSTRUCT1)
to
shreyas[0].UnionAttr->struct1 = (MYSTRUCT1 *) malloc (sizeof(MYSTRUCT1)
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;
[Code] ....
View 3 Replies
View Related
Jan 24, 2014
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.
Game.h
#ifndef GAME_H
#define GAME_H
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "Graphics.h"
#include <string>
#include <cstring>
using namespace std;
//GLOBAL CONSTANTS
//game window settings
[Code] ....
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.
View 3 Replies
View Related
Feb 28, 2015
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.
main.cpp
#define GLEW_STATIC
#include <glew.h>
[Code].....
View 2 Replies
View Related
May 17, 2014
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
[Code]....
I know it has to do with the array, and I've tried over and over again to fix my issue and nothing has worked thus far.
View 3 Replies
View Related
Apr 29, 2014
I have a very strange problem with the system() function (on XP).
I have the following code:
Code:
char *text1 = ""A SpaceAction.bat" fred";
char *text2 = ""A SpaceAction.bat" "fred"";
int main(int argc, char *argv[]) {
printf("%s
", text1);
[Code] .....
When I run it where "A Space" is a directory with a space in the name, this is the result:
Code:
"A SpaceAction.bat" fred
F:Test>echo Testing
Testing
"A SpaceAction.bat" "fred"
'A' is not recognized as an internal or external command, operable program or batch file.
It seems that the double quotes round an argument make the parsing of the command fail.
View 1 Replies
View Related
Oct 15, 2013
I have a few VC2008 projects whose solutions also includes deployment projects, in which the primary output of several DLLs are included along with the primary apps EXE file. These DLLs are all part of the solution. Now because of the way I do my DLLs, which for lack of better phrase I'll call a true DYNAMIC link (the .LIB file can be discarded), and because I'm careful to ensure full backward compatibility in any new DLL versions, I would like to tell my deployment project to ALWAYS replace existing DLLS with the new versions, or at least offer a choice if it shouldn't be done unconditionally. Unfortunately it never seems to do that!
I'm being careful to create new overall project versions within the deployment project itself, as well as keeping my version resources, attached to each DLL up to date, and always do a full rebuild of everything in the solution (including the DLLs) prior to building the deployment project. But time and again the old DLLs stay un-updated after the install, and the person running it would have no way to know that without examining the target directories and examining file dates and/or versions. A customer shouldn't have to go through all that. I've gotten into the habit of instructing installers to fully un-install old versions before installing a new one, but as you probably know uninstalling from the control panel won't remove shared DLLs.
I was starting to think maybe the latest DLLs weren't being included in the deployment project at all. But if I manually delete those DLLS and do the install, the latest greatest are then always placed.
If I can't find a setting in the deployment project to change this behavior, I'll have to write a separate little console app to force delete (or at least archive) all the relevant DLLs as a pre-installation step. Or maybe supply a BATCH file to do all that, and run the install last. But it seems like a reasonable thing that a setting to make a deployment (MSI) file unconditionally overwrite DLLS, whose version or creation date is newer, ought to be an obvious feature. But if such an option exists, I've missed it completely.
View 5 Replies
View Related
Dec 17, 2014
I'm trying to implement a T9 (predective text) project in c++ using k-ary Tree.
I would like to understand how can I add the words in the Tree and how can I display them later.
inside each node of the tree I have a linked list (for the words) and a vector of pointers to access the next node
Here are my structs :
struct NodeList{
string data;
NodeList * next;
};
struct List{
NodeList *head;
[code].....
View 1 Replies
View Related
Mar 1, 2014
Today I am refining my skills on graph theory and data structures. I decided to do a small project in C++ because it's been a while since I've worked in C++. I want to make an adjacency list for a directed graph. In other words, something which looks like: 0-->1-->3 1-->2 2-->4 3--> 4-->This would be a directed graph with V0 (vertex 0) having an edge to V1 and V3, V1 having an edge to V2, and V2 having an edge to V4, like this:
V0----->V1---->V2---->V4
|
|
v
V3
I know that in order to do this, I will need to create an adjacency list in C++. An adjacency list is basically an array of linked lists. Okay, let's see some pseudo C++ code:
Code:
#include <stdio>
#include <iostream>
using namespace std;
struct graph{
[Code] ....
This pseudocode is currently far from the mark. And that is what -- pointers and structs in C++ have never been my strong suit. First of all, this takes care of the vertices that a vertex points to -- but what about the vertex itself? How can I keep track of that vertex? When I loop over the array, it will do me no good to only know what vertices are being pointed to, rather than also knowing what points to them. The first element in each list should probably be that vertex, and then the elements after that are the vertices it points to.
But then, how can I access this first element of the list in my main program?. I would like to be able to loop over this adjacency list to do some cool things with graphs. For example, to implement some graph theory algorithms (sorts, shortest paths, etc) using the adjacency list representation. (Also, I had a question about the adjacency list. What is different than just using a list of arrays? Why can't I just have a list with an array at each element in the list?)
View 2 Replies
View Related
Jul 6, 2014
I am an experience C programmer but never implement GUI.
I need to make a demo implementation that will be run on Linux and will implement GUI.
I searched the WEB and found lot of information, among is implementing the GUI in HTML and run the API through web browser.
How can I make such implementation in C?
View 2 Replies
View Related
Mar 19, 2013
Implement ksmall as a C++ function. Use the first item of the array as the pivot. This is what I have so far, but everytime I compile it crashes ....
#include <cstdlib>
#include <iostream>
using namespace std;
int kSmall(int k, int anArray[], int first, int last);
[Code] ....
View 4 Replies
View Related
Feb 24, 2013
i want to implement dfa that accepts the binary string with at least two 0's after every 1 .....
View 3 Replies
View Related