mercredi 1 juillet 2015

Not able to understang this concept of handlers in c++

I was going through a piece of code where I came across something new.However I tried to write my own code for better understanding.

#include<iostream>

using namespace std;

class material
{
public:
material()
{
    cout<<"material() called"<<endl;
}

bool test_func()
{
    cout<<"Hello World"<<endl;

    return true;
}
};

class server
{
private:
material *mat;

public:
server()
{
    cout<<"server() called"<<endl;
}
material *matrl()
{
    return mat;
}
};

class Handler
{
public:
Handler()
{
    cout<<"Handler() called"<<endl;
}

server svr;

bool demo()
{
    bool ret;
    ret=svr.matrl()->test_func();

    return ret;
}
};

int main()
{
Handler h;
cout<<"returned by demo():"<<h.demo()<<endl;

return 0;
}

Even I am getting the desired output, which is:

server() called
Handler() called
Hello World
returned by demo():1

But I am not able to understand certain concepte over here,like

material *matrl()
{
    return mat;
}

and the call

ret=svr.matrl()->test_func();

How this is working and what concept is this.Can somebody help me with this???

When using IBO/EBO, program only works when I call glBindBuffer to bind the IBO/EBO AFTER creation of the VAO

For some reason, this program only works when I bind the IBO/EBO again, after I create the VAO. I read online, and multiple SO posts, that glBindBuffer only binds the current buffer, and that it does not attach it the the VAO. I thought the glVertexAttribPointer is the function that attached the data to the VAO.

float points[] = {

   -0.5f,  0.5f, 0.0f, // top left      = 0
    0.5f,  0.5f, 0.0f, // top right     = 1
    0.5f, -0.5f, 0.0f, // bottom right  = 2
   -0.5f, -0.5f, 0.0f, // bottom left   = 3

};

GLuint elements[] = {

    0, 1, 2,
    2, 3, 0,
};

// generate vbo (point buffer)
GLuint pb = 0;
glGenBuffers(1, &pb);
glBindBuffer(GL_ARRAY_BUFFER, pb);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);

// generate element buffer object (ibo/ebo)
GLuint ebo = 0;
glGenBuffers(1, &ebo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

// generate vao
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);


glBindBuffer(GL_ARRAY_BUFFER, pb);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);


glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); // when I bind buffer again, it works


glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

If I did not have the second glBindBuffer, the program crashes. All I want to know is why I have to call glBindBuffer again, after I create the VAO, when calling glBindBuffer only makes the buffer the active buffer for other functions.

Pastebin (FULL CODE)

digital signature implementation in c++

this will be my first question here...soo plzz kndly help me...am in urgent need of this!

so i have to develop a c++ code for implementation of digital signatures. i understand the basic concept of it...but am kind of a noob wen it comes to c++ coding...sopoo can someone pllzz tell me step by step procedure of how to develop a code for digitaly signing a databse and den a code for verifying that previously signed database. sooo far wat i have done is: 1. created a databse using microsoft sql server 2. have found a library only for hashin which contains hashing function(m facing a problem here . the function sha256() requires to pass the databse as an arguement i dnt know how to do dat soo plzz if u can guide me through dis also) 3. i ll be provided with a doungle containing my private key for signing of the document. preferably i ll be using rsa signing.

sooo this wat i did and know abt dis project of mine...

i request to person answering to be exclusive and xplain in detail to how to approch and code dis in c++ as i a dnt possess ant thorogh knowledge of dis topic thank you!

How to fix the armadillo library to c++

I'm using a macbook to program some bits of code here and there. Recently I wanted to do something in C++ together with the armadillo library... but after installation and everything it doesn't seem to work...

For instance I can write arma::mat variable, etc but when I run this code in TextMate:

vec q = randu(5);

cout << normalise(q);

I get this error output:

"Undefined symbols for architecture x86_64: "_wrapper_dgesdd_", referenced from: void arma::lapack::gesdd(char*, int*, int*, double*, int*, double*, double*, int*, double*, int*, double*, int*, int*, int*) in test-56d704.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) rm: /var/folders/sh/vr2n15ln47j0k33yh1j0_tyw0000gn/T/test.cpp.Sfz5vezN: No such file or directory

The weird thing is that if I don't use the normalise or norm functions it compiles well..

I include the library as #include '/usr/local/include/armadillo'

Please help!

Edit: I've installed the armadillo package both trying with "brew install armadillo" but also with the steps mentioned in the README.txt if you download armadillo from their webpage. I'm at a total loss..

C++ can't implement default constructor

I have a class:

class Fraction {
    private:
        int x;
        int y;
    public:
    // Constructors
        Fraction(long x = 0, long y = 1);
        Fraction(const Fraction&)=default;//here is the problem
        virtual ~Fraction();
 };

And I'm trying to disable default C++ constructor for copy, to do my own. So, I declared it as a default. But, when I'm trying to implement it:

Fraction::Fraction(const Fraction&){}

Compiler throws some errors at me.

./src/Fraction.cpp:16:1: error: definition of explicitly-defaulted ‘Fraction::Fraction(const Fraction&)’ Fraction::Fraction(const Fraction&){ ^ In file included from ../src/Fraction.cpp:8:0: ../src/Fraction.h:22:2: error: ‘Fraction::Fraction(const Fraction&)’ explicitly defaulted here Fraction(const Fraction&)=default;

Is there any way to fix it? What I'm doing wrong, I found some articles about defaults, but nothing that can help me to fix these errors.

QString functions giving incorrect results on CentOS

I am using C++ Qt Library and following code is working perfectly on Windows but not working on CentOS :

if(line.startsWith("[", Qt::CaseInsensitive))
                        {
                            int index = line.indexOf(']', 0, Qt::CaseInsensitive);
                            QString subLine = line.mid(index+1);
                            subLine = subLine.trimmed();
                            tokenList = subLine.split("\t");
                        }
                        else
                        {
                            tokenList = line.split("\t");
                        }

I have a line [ x.x.x.x ] something ../dir/file.extension and i want to ignore the [x.x.x.x] part while breaking line into tokens. I ma using VC9 on windows to debug and its working fine.

Double-checking understanding of memory coalescing in CUDA

Suppose I define some arrays which are visible to the GPU:

double* doubleArr = new double[fieldLen];
float* floatArr = new float[fieldLen];
char* charArr = new char[fieldLen]

Now, I have the following CUDA thread:

void thread(){
  int o = getOffset(...);
  double d = doubleArr[threadIdx.x + o];
  float f = floatArr[threadIdx.x + o];
  char c = charArr[threadIdx.x + o];
}

I'm not quite sure whether I correctly interpret the documentation, and its very critical for my design: Will the memory accesses for double, float and char be nicely coalesced? (Guess: Yes, it will fit into sizeof(type) * blockSize.x / (transaction size) transactions, plus maybe one extra transaction at the upper and lower boundary.)

Furthermore, suppose I also have a struct:

struct char3{
  char a;
  char b;
  char c;
}

char3* char3Arr = new char3[fieldLen];

I guess this will be padded and aligned to 32 bit and then consume fieldLen*4 bytes in memory and coalesce the same way as a float?

What is wrong with this approach of copy and assignment? [duplicate]

This question already has an answer here:

#include <iostream>
#include <vld.h>

using namespace std;

class MyClass
{
private:
    int x;
    int y;
    int z;
private:
    void Copy(const MyClass & rhs) throw ()
    {
        x = rhs.x;
        y = rhs.y;
        z = rhs.z;
    }
public: 
    MyClass()
    {
        x = 0;
        y = 0;
        z = 0;
    }
    ~MyClass()
    {
        x = 0;
        y = 0;
        z = 0;
    }
    MyClass(const MyClass & rhs)
    {
        Copy(rhs);
    }
    MyClass & operator=(const MyClass & rhs)
    {
        Copy(rhs);

        return *this;
    }
    void Set(int a, int b, int c)
    {               
        x = a;
        y = b;
        z = c;
    }
    void Show(void) const 
    {
        cout<<x<<", "<<y<<", "<<z<<endl;
    }
};

int main()
{
    MyClass o1;
    o1.Set(10, 20, 30);
    o1.Show();

    MyClass o2(o1);

    o1 = o2;

    o1.Show();
}

Why is this std::unique_ptr being returned without a std::move statement

I am trying to familiarize my self with the std::unique_ptr and I understand that these pointers can only be moved. This is the code that I am trying out

struct foo
{
    int a;
};

std::unique_ptr<foo> GetPointer()
{
    std::unique_ptr<foo> f(new foo());
    return f;
}

int main()
{
    std::unique_ptr<foo> m = GetPointer();
}

I am using the flag -fno-elide-constructors to disable compiler optimization that reduces the copies made. My question is why is the f being returned ? It is an lvalue so I am assuming it cannot be moved. I was expecting to get an error because of return f and I was under the impression it should be return std::move(f)

What is my code missing. no match for 'operator<<' in 'std::cout << vals' [duplicate]

This question already has an answer here:

#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

struct twoVals
{
        int x;
    double y;
} number;

int main()
{
    number.x = 10;
    number.y = 20;

twoVals vals;
cout << vals << endl;

return 0;

}

Line 19: error: no match for 'operator<<' in 'std::cout << vals' compilation terminated due to -Wfatal-errors.

That is the error I get. How do I fix this? Is there anything else wrong with my code? Give examples.

Linker Error 2019 without touching the linker properties?

So I'm making a game, and it was working perfectly fine, so I started developing the next part of the game which is the chunking system and the generation (you might be able to tell from my previous posts) but then all of a sudden I got some random linker errors, even though I haven't touched anything in the linker and the game was working perfectly fine before. Here are the errors:

Error   3   error LNK2019: unresolved external symbol "public: class sf::Sprite __thiscall AbstractBlock::draw(void)" (?draw@AbstractBlock@@QAE?AVSprite@sf@@XZ) referenced in function _main   C:\(Insert personal stuff here)\Main.obj    Top Down Shooter
Error   4   error LNK2019: unresolved external symbol "public: void __thiscall AbstractBlock::destroy(class b2World *)" (?destroy@AbstractBlock@@QAEXPAVb2World@@@Z) referenced in function "public: int __thiscall Universe::saveGame(void)" (?saveGame@Universe@@QAEHXZ)  C:\(Insert personal stuff here)\Universe.obj    Top Down Shooter
Error   5   error LNK1120: 2 unresolved externals

They don't have line numbers and it appears the problem is in the Universe.obj and main.obj? I honestly don't know what those are, so instead I'm going to post both of the .cpp files in full:

Universe.cpp:

#include "Universe.h"

Universe::Universe(){

    world = new b2World(b2Vec2(0, 0));
    world->SetAllowSleeping(false);

    chunkManager = new ChunkManager(world);

    player = new Player(world);


}


Universe::~Universe()
{
}

int Universe::saveGame(){
    player->destroy(world);
    player = nullptr;


    std::list<AbstractBlock>::iterator i;

    for (i = getLoadedBlocks()->begin(); i != getLoadedBlocks()->end(); i++){
        i->destroy(world);
    }

    world = nullptr;
    return 1;
}

void Universe::spawnEntity(int x, int y, int entityID){

}

std::list<AbstractBlock>* Universe::getLoadedBlocks(){
    return chunkManager->getLoadedBlocks();
}

void Universe::update(){

    player->update();

    world->Step(1 / 60.f, 8, 3);
}

Player* Universe::getPlayer(){
    return player;
}

Main.cpp:

#include <iostream>
#include "Box2D\Box2D.h"
#include "SFML/Graphics.hpp"
#include "Universe.h"
#include "simplexnoise.h"

int main(){

    static int FPS = 1.f / 60.f;

    sf::RenderWindow window(sf::VideoMode(640, 480), "Top Down Shooter");
    sf::Event event;

    Universe universe;

    bool running = true;
    int distX;
    int distY;
    float angle;

    while (running){

        window.clear(sf::Color::White);

        while (window.pollEvent(event)){
            switch (event.type){
            case sf::Event::Closed:
                running = false;
                break;
            case sf::Event::KeyPressed:
                switch (event.key.code){
                case sf::Keyboard::Q:
                    running = false;
                    break;
                case sf::Keyboard::W:
                    universe.getPlayer()->setMoveUp(true);
                    break;
                case sf::Keyboard::A:
                    universe.getPlayer()->setMoveLeft(true);
                    break;
                case sf::Keyboard::D:
                    universe.getPlayer()->setMoveRight(true);
                    break;
                case sf::Keyboard::S:
                    universe.getPlayer()->setMoveDown(true);
                    break;
                }
                break;
            case sf::Event::KeyReleased:
                switch (event.key.code){
                case sf::Keyboard::W:
                    universe.getPlayer()->setMoveUp(false);
                    break;
                case sf::Keyboard::A:
                    universe.getPlayer()->setMoveLeft(false);
                    break;
                case sf::Keyboard::D:
                    universe.getPlayer()->setMoveRight(false);
                    break;
                case sf::Keyboard::S:
                    universe.getPlayer()->setMoveDown(false);
                    break;
                }
                break;

            }


        }

        distX = (sf::Mouse::getPosition().x - universe.getPlayer()->getXpos() - window.getPosition().x - 10);
        distY = (sf::Mouse::getPosition().y - universe.getPlayer()->getYpos() - window.getPosition().y - 30);
        if (distX != 0){
            angle = std::atan2f(distY, distX);
            universe.getPlayer()->setAngle(angle + (b2_pi / 2));
        }

        //Updating the universe
        universe.update();

        //Drawing Everything
        window.draw(universe.getPlayer()->draw());

        std::list<AbstractBlock>::iterator i;

        for (i = universe.getLoadedBlocks()->begin(); i != universe.getLoadedBlocks()->end(); i++){
            window.draw(i->draw());
        }




        window.display();


    }

    universe.saveGame();

    return 0;
}

So I was trying to figure out the problem on my own, and I thought it may have been the part where I use the iterator and the lists to draw all the current blocks in the universe. I thought this because both the Universe and main .cpp have these small for loops in them (which I just recently added). So I commented out those parts in each file and things got even weirder. Visual Studio 2013 then gave me errors when I ran my program and then would take me to xutility file! I have no idea why! I made sure to comment out the iterator part and tried again but the same thing happened! With those two lines of iterators commented out I'm not using iterators at all in my program! Why would it be taking me to there? Please help i'm so confused >.<

Defining a Discrete Probability Distribution in C++

I have been trying to create my own discrete distribution in Visual Studio (C++). I kept getting the same error. I then tried the example code from: http://ift.tt/1R6pjgK.

Again, the same error appeared with this example code.

The line of code (from the link) that is giving me an error is:

std::discrete_distribution second(init.begin(), init.end());

Particularly, init.begin() is underlined in red.

The 2 errors are as follows:

2 error C2661: 'std::discrete_distribution::discrete_distribution' : no overloaded function takes 2 arguments

3 IntelliSense: no instance of constructor "std::discrete_distribution<_Ty>::discrete_distribution [with _Ty=int]" matches the argument list argument types are: (std::_Array_iterator, std::_Array_iterator)

Why would my compiler not work? I am wondering if other people are getting the same errors? I also just updated my version of Visual Studio to make sure it wasn't an old bug

method binding in C++

class Shape {
    public:
        virtual void draw() = 0;
        virtual void area() { . . .}
        . . .
};

class Circle : public Shape {
    public:
        void draw() { . . . }
        . . .
};

class Rectangle : public Shape {
    public:
        void draw() { . . . }
        . . .
};

class Square : public Rectangle {
    public:
        void draw() { . . . }
        . . .
};

Rectangle* r = new Rectangle;
r->draw(); // (1)

r = new Square;
r->draw(); // (2)

Shape* sh = new Circle;
sh->area(); // (3)

Square* sq = new Square;
sq->draw(); // (4)

(1),(2) dynamic binding, there's no doubt i think

(3) Since any class derived from Shape don't override the method area, it's resolved to Shape::area() by compiler?

(4) No class derived from Sqaure class, sq can only reference Square type, it means static method binding occurs?

Is there anything wrong?? thanks in advance.

Universal references with functions

What is the type of "univ" in the code below?

template<typename T>
void func(T&& univ) {
    // ??
}

int sum(int a, int b) {
 return a+b;   
}

int main() {

    func(sum);

}

I didn't know that universal references also worked with functions. Is func(sum); equivalent to func(&sum); or is the rvalue reference binding itself to something else than a simple pointer?

String vector to 3D char vector

I'm new to C++ and this is my first attempt at a 3D vector. I'm trying to take an input file like this:

xxooo##xx
xoxxxoxoo
xxx#oxoo#
oxxxoxoox
xxoooo#xx
xxxo#o###
xxo#o#xxo
x##oxxoox
xxx##oxoo
xoxx#xooo

And turn it into a 3D char vector where each line is a 3x3 box with the first three characters being the first row, the next three the 2nd row, and the last three the 3rd row. For example the first row of the input should turn into this:

x x o
o o #
# x x

This is my attempt at a solution, but I feel that I've probably made several mistakes:

vector<vector<vector<char> > > makeBoard(vector<string> iflines)
{// Function to fill game boards from input strings

vector<vector<vector<char> > > charboard;

for (int i = 0; i != iflines.size(); i++) 
{   
    for (int j = 0; j < 9; j++)
    {
    charboard[i][j/3][j%3] = iflines[i][j];         
    }   
}
    return charboard;
}

Would someone please help me out here?

Invisible differences in XML files - breaking self-made XML parser

I have two programs that interact with an well-defined XML file. The first program (Model) reads it in, parses it, and uses content from the file to direct the running of a model. The second program (Controller) opens up and rewrites the XML file, allowing different settings to be run in the Model.

Model is written in C++, worked with in VS2010 and VS2012, has no GUI, and uses a home-made (is this the correct term?) XML parser that has worked for many years without fail - I just checked the SVN for revisions to the files that make it up - nothing since 2013. Controller is written in C#, in VS2012, with a GUI that has drop downs that set the content of the XML file, and uses the XmlDocument class to read in, edit, and print out the XML file .

Suddenly, the Controller no longer spits out XML files that can be read by Model. When Model tries to read the XML file, the first character it encounters it reads as '-17'. AS far as I have been able to tell this means that it doesn't recognize it as an UTF-8 character. This cause model to cout the error and then crash. Older XML file (which looks identical to the ones written by Controller) reads in fine.

Below are examples of the files - ignore the content inside the elements please.

Older file:

<?xml version="1.0" encoding="UTF-8" ?> 
<Config>
<Mode value="false" Id="Modeflag" />
<Timestep OutputTimestep="Hourly"  CalibrationTimestep="Daily" />
<InitialInput SubCatchmentNumber="1" ModelCalibration="true" SnowSimulation="false" VegSimulation="Method 1" CatchmentNumber="1" FractionalCatchmentArea="1" />
<InputResource Name="All" Location="C:\Hydro_Code\Hydro_Test_Files\Inputs\V5HarborBrookWeek_Rain" Id="Directory" />
<SimulationScheme SchemeForCatchmentNo="8" Infiltration="true" ChannelRouting="false" Saturation="true" TopographicIndex="true" KDecayWithSoilDepthExp="false" SoilTopoIndex="false" KDecayInPower="true" />
<SnowInput InputCatchmentNumber="1" TempIndexMethod_Hourly="false" RadiationTempIndex_With_SnowInterception="true" EnergyBudgetMethod_With_SnowInterception="false" />
<SnowInputResource Name="All" Location="C:\Hydro_Code\Hydro_Test_Files\Inputs\V5HarborBrookWeek_Rain" Id="SnowDirectory" />
<OutputDirectory Location="C:\Hydro_Code\Hydro_Test_Files\Inputs\V5HarborBrookWeek_Rain\Outputs" Name="Toronto_Output" />
</Config>

Newer file:

<?xml version="1.0" encoding="UTF-8" ?>
<Config>
  <Mode value="false" Id="Modeflag" />
  <Timestep OutputTimestep="Hourly" CalibrationTimestep="Hourly" />
  <InitialInput SubCatchmentNumber="1" ModelCalibration="true" SnowSimulation="false" VegSimulation="Method 1" CatchmentNumber="1" FractionalCatchmentArea="1" />
  <InputResource Name="All" Location="C:\AutoRun_Newest\AutoRun" Id="Directory" />
  <SimulationScheme SchemeForCatchmentNo="8" Infiltration="true" ChannelRouting="false" Saturation="true" TopographicIndex="true" KDecayWithSoilDepthExp="false" SoilTopoIndex="false" KDecayInPower="true" />
  <SnowInput InputCatchmentNumber="1" TempIndexMethod_Hourly="false" RadiationTempIndex_With_SnowInterception="true" EnergyBudgetMethod_With_SnowInterception="false" />
  <SnowInputResource Name="All" Location="C:\AutoRun_Newest\AutoRun" Id="SnowDirectory" />
  <OutputDirectory Location="C:\AutoRun_Newest\Inputs\Output_Timestamp_07012015215112" Name="Toronto_Output" />
</Config>

Adding or taking away the indentation (proper formatting by the XmlDocument class in C#) changes nothing about the behavior of Model.

These files are visually identical, and I can see no odd characters or spacing. What invisible objects/forces/characters or other settings could be causing this new bug?

Is there some background encoding that the XML document class enforces that is new to my home made parser?

Passing C++ character array to Fortran

I have been trying to pass a character array from C++ to a Fortran subroutine but it seems like Fortran does not receive characters properly. I have been searching the web to find a solution but proposed ideas seem to be too complicated. An interesting (and concise) solution was proposed by Steve at Intel Fortran Forum but I cannot get it work in my code. So, I appreciate any suggestion to help me out to resolve this issue.

The following function is my C++ routine that makes call to fortran subroutines:

extern "C" void __stdcall F_VALIDATE_XML(const char* buffer, int len);
void CUDMEditorDoc::OnValidateXML()
{
    CString fileName = "test.udm";
    const char* buffer = fileName.GetBuffer();
    int len = fileName.GetLength();
    F_VALIDATE_XML(buffer, len);
}

And here is the Fortran subroutine that is supposed to receive character array:

subroutine validate_xml(file_name, len)
!DEC$ ATTRIBUTES DECORATE, STDCALL, ALIAS:"F_VALIDATE_XML" :: validate_xml

use xml_reader_structure
use, intrinsic :: ISO_C_Binding

integer(C_INT), value, intent(in) :: len
character(len, kind=C_CHAR), intent(in) :: file_name

integer  :: i
i = 1
end subroutine validate_xml

In debug mode and when the program has stopped at line (i = 1), I hover mouse over file_name to see its contents but the Watch window says that it cannot find file_name symbol (although len is correctly passed). Also, if I watch file_name(1:8) in watch window, still I don't get the original character arrays. I believe there is something wrong with the way I pass parameters to Fortran but chances are Watch Window is not correct.

I appreciate any help that could shed some lights here. Thanks

Define an object in a .cpp file

Header file

class Universe
{
    public:
        Universe();
        ~Universe();

    private:
        ChunkManager chunkManager;
};

I want to initialize chunkManger without using the default constructor. However, the constructor I want to use takes an object. How do I make the chunkManager object to use the correct constructor in the .cpp file? So I want something like this:

Universe::Universe(){

    world = new b2World(b2Vec2(0, 0));
    world->SetAllowSleeping(false);

    //I want something like this because the constructor I want takes a World object
    chunkManager = new ChunkManager(world);

    player = new Player(world);
}

"Read" does not name a type

I have been writing a program which requires me to take input from the serial monitor in Arduino. However I'm having some problems. Here's my code. #include

int R1 = 20;
int R2_2 = 20;
int R4_7 = 20;
int R5_6 = 20;
int R7_5 = 20;
int R8_2 = 20;
int R10 = 20;
int R15 = 20;
int R22 = 20;
int R27 = 20;
int R33 = 20;
int R39 = 20;
int R47 = 20;
int R56 = 20;
int R68 = 20;
int R75 = 20;
int R82 = 20;
int R100 = 20;
int R120 = 20;
int R150 = 20;
int R180 = 20;
int R220 = 20;
int R270 = 20;
int R330 = 20;
int R390 = 20;
int R470 = 20;
int R510 = 20;
int R680 = 20;
int R820 = 20;
int R1k = 20;
int R1k5 = 20;
int R2k2 = 20;
int R3k3 = 20;
int R3k9 = 20;
int R4k7 = 20;
int R5k6 = 20;
int R6k8 = 20;
int R7k5 = 20;
int R8k2 = 20;
int R10k = 20;
int R15k = 20;
int R22k = 20;
int R33k = 20;
int R39k = 20;
int R47k = 20;
int R56k = 20;
int R68k = 20;
int R75k = 20;
int R82k = 20;
int R100k = 20;
int R150k = 20;
int R180k = 20;
int R220k = 20;
int R330k = 20;
int R470k = 20;
int R560k = 20;
int R680k = 20;
int R1m = 20;
int R1m5 = 20;
int R2m = 20;
int R3m3 = 20;
int R4m7 = 20;
int R5m6 = 20;
int R10m = 20;
int AClips = 11;
int Blue_LED = 50;
int RGB_LED = 1;
int Yellow_LED = 10;
int Red_LED = 16;
int Button = 102;
int Carbon_Film = 2;
int Ambient_Light_Sensor = 10;
int Laser_Diode = 9;
int photocell = 1;
int Piezo_Buzzer = 1;
int Relay = 1;
int Transistor_2N2222A = 1;
int Transistors = 0 + Transistor_2N2222A;
char searchedItem[200];

This next line is the line that was highlighted: read.Serial(searchedItem);

void setup() {
//setup code here, to run once:
Serial.begin(9600);
}

void loop() {
//loop code here, to run forever:
if (searchedItem == "Red LED"); {
if (searchedItem => 1); {
  Serial.println("\nFound!\nYou have ", Red_LED, "Red LEDs");
    }
  }
}

c++ sqlite3_prepare_v2 is not working

this is my first post so excuse me if I forget to add some information, or my english mistakes.

I m working in c++ with code:block(13.12) making a DLL of sqlite3 functions and using MinGW toolchain. (windows 7)

I was using sqlite3_exec function but i want to change to sqlite3_prepare_v2, sqlite_bind.., sqlite3_step, etc because I think it will be easy to get back the return params. However, after calling that new function from another program written also in c++, it crash giving me this error:

  Nombre del evento de problema:  APPCRASH
  Nombre de la aplicación:    SQL_try.exe
  Versión de la aplicación:   0.0.0.0
  Marca de tiempo de la aplicación:   5594a5af
  Nombre del módulo con errores:  sqlite3.dll
  Versión del módulo con errores: 3.8.10.2
  Marca de tiempo del módulo con errores: 555cd28a
  Código de excepción:    c0000005
  Desplazamiento de excepción:    0001ee21
  Versión del sistema operativo:  6.1.7601.2.1.0.768.3
  Id. de configuración regional:  3082
  Información adicional 1:    0a9e
  Información adicional 2:    0a9e372d3b4ad19135b953a78882e789`
  Información adicional 3:    0a9e
  Información adicional 4:    0a9e372d3b4ad19135b953a78882e789

I can not easily depurated it because I m not use to code:block and also I m calling the function from a DLL.

This is the function I m using, that i get it from this other post:[Proper use of callback function of sqlite3 in C++

string DLL_EXPORT readFromDB(sqlite3* db, int id)
{   string result;
    sqlite3_stmt *stmt;
     const char *sql="SELECT name FROM datos WHERE id = ?";
    int rc = sqlite3_prepare_v2(db, sql,-1 , &stmt, NULL);
    if (rc != SQLITE_OK)
        return string(sqlite3_errmsg(db));

    rc = sqlite3_bind_int(stmt, 1, id);    // Using parameters ("?") is not
    if (rc != SQLITE_OK) {                 // really necessary, but recommended
        string errmsg(sqlite3_errmsg(db)); // (especially for strings) to avoid
        sqlite3_finalize(stmt);            // formatting problems and SQL
        return errmsg;                      // injection attacks.
    }

    rc = sqlite3_step(stmt);
    if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
        string errmsg(sqlite3_errmsg(db));
        sqlite3_finalize(stmt);
        return errmsg;
    }
    if (rc == SQLITE_DONE) {
        sqlite3_finalize(stmt);
        return string("customer not found");
    }

    result= string((char *)sqlite3_column_text(stmt, 0))+ " ";
   // *result=*result + string((char*)sqlite3_column_text(stmt, 1)) +" ";
    //*result=*result + string((char*)sqlite3_column_int(stmt, 2));

    sqlite3_finalize(stmt);
   return result;
}

I m calling the DLL function with:

mifunc5=(Myfunc5)GetProcAddress(  histDLL,"readFromDB");
   aString=(mifunc5)(db,1);

An I don't think that the problem is that the db is not loaded, beacuse the other functions works and i tryed to comment all except the sqlite3_prepare_v2 and sqlite3_finalize funtions, neither works.

Thank you very much for your attention. :)