Latest Software Development Posts

In your original functions, I would pass the std::vectors by reference, not by value. If a value is not expected to change, apply a const modifier to the argument. Now the compiler will warn you if you try to change it. Do not use the same name for your data members as the function parameter that is being used to manipulate it; you are just asking for confusion.

In general, converting this kind of C++ code to C would need you to:

  • Convert all class definitions to struct definitions (simple enough).
  • Redefine any member function into a regular function, taking your struct instance as a parameter, maybe a pointer to the struct instance if you need to modify the original struct.
  • Remove all constructors and destructors. The beautiful automatic allocation and clean-up provided by these member functions must be managed seperately in C.
  • All local variable declarations must be at the beginning of your functions, before any executable statements. In C++ you can declare variables and objects anywhere inside the function, even inside flow-control structures like loops.
  • public member functions should be declared in a header (.h) file so they can be #include'd in other source files in your project.
  • private or protected member functions should be declared only in the source (.c) file with a static modifier to indicate that the function can not be called outside of that source file.
  • cout >> calls get converted to puts() and printf() calls. The ...

fflush() on an input thread is not actually defined in the C standard, thus its behaviour is compiler-dependant. It would be nice if it cleared an input buffer, but for most compilers, it does nothing. It won't fail, but it does not clear the buffer either. The behaviour of fflush() is only defined in the standard for an output buffer.

The #define pre-preprocessor directive does a text replacement for the rest of the source file, prior to the compiler itself getting the source file to parse. The only difference I can see is that your wait() #define has curly braces around it, but when used on its own, you left those out.

What part are you having trouble with?

commented: I have problem with making Cell class and properties and queue too. +0

I have a C++ program :

// ConsoleApplication14.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>
#include <list>
#include <queue>
#include <vector>
#include <string>

using namespace std;
class RectangularVectors
    static std::vector<std::vector<int>> ReturnRectangularIntVector(int size1, int size2)
        std::vector<std::vector<int>> newVector(size1);
        for (int vector1 = 0; vector1 < size1; vector1++)
            newVector[vector1] = std::vector<int>(size2);

        return newVector;
    static std::vector<std::vector<bool>> ReturnRectangularBoolVector(int size1, int size2)
        std::vector<std::vector<bool>> newVector(size1);
        for (int vector1 = 0; vector1 < size1; vector1++)
            newVector[vector1] = std::vector<bool>(size2);

        return newVector;

class Cell {
    int x;
    int y;
    int dis;
    Cell(int x, int y,  int dis);  // This is the constructor

// Member functions definitions including constructor
Cell::Cell(int x, int y, int dis) {
    this->x = x;
    this->y = y;
    this->dis = dis;

int minStepToReachTarget(std::vector<int> knightPos, std::vector<int> targetPos, int N, int M);

int main()
    int n, m, r, c;
    cout << "Enter the number of rows : ";
    cin >> n;
    cout << "Enter the number of cells : ";
    cin >> m;
    cout <<  "Enter the number of knight position row : ";
    cin >> r;
    cout << "Enter the number of knight position cell : ";
    cin >> c;
    std::vector<std::vector<int>> Moves = RectangularVectors::ReturnRectangularIntVector(n, m);
    std::vector<int> knightPos = { r - 1, c - 1 };
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            std::vector<int> targetPos = { i, j };
            Moves[i][j] = ...

You left me confused. You wrote you don't share code then proceed to try to use shared code.

Beyond that, the C code you shared looks to be old command line stuff and no indication a windows system was in use.

For decades when I ran a small C app from the command line to today, it's the same as it was 2 decades plus ago with an exception I might be using Gnome or another system. Just open a bash shell, run the command or C app and all is fine. Not once does the base shell in a window system close on me.

I am doing a team project with some people that prefer Linux and some people prefer Windows. We are also not allowed to share code for security reasons. One thing the Windows people love to whine about is a way to hold the window open. So the way they usually solve the problem is with:

#include <conio.h>

This creates a problem for the Linux users since we do not have that library. I have been looking for ways to solve this problem and I really like this idea.

#include <stdlib.h> //For system commands

//Detect and define which command to use
#ifndef WIN32
    #define COMMAND "clear" //Clears a linux console screen
    #define COMMAND "cls" //Clears a windows console screen

#define wipe() system( COMMAND )
//To clear the console screen use wipe();

#define wait() {printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);}
//To pause the program or hold the console screen open use wait();

This seems to work when I use #defines but not when I just use this line:

printf("Hit \"Enter\" to continue\n");fflush(stdin);getchar();fflush(stdin);

Since I know most of the programmers pretty well I know they use scanf so I added this and it worked:

while ((getchar()) != '\n'); 

Why did the #defines work without the extra while loop, but I needed the extra while loop when not using the #defines? Do #defines behave a little different? I can not look at the others peoples code unfortunately. Is there a better way to solve the problem of holding the window open for ...

The PHP and C/C++ NetBeans bundles only require the Java Runtime Environment (JRE) 7 or 8 to be installed and run. JDK 7 or 8 is required if you are planning to use any of the Java features. JDK 7 Update 6 (or newer) is required to use JavaFX 2.2 (or newer) features in NetBeans IDE 8.1[Click Here](The PHP and C/C++ NetBeans bundles only require the Java Runtime Environment (JRE) 7 or 8 to be installed and run. JDK 7 or 8 is required if you are planning to use any of the Java features. JDK 7 Update 6 (or newer) is required to use JavaFX 2.2 (or newer) features in NetBeans IDE 8.1)

commented: I too have run into folk that install some Java app but forgot to install Java itself. +15


I am trying to get windows positioned in specific order as show below


but I am unable to get and get always this


the code below is shown

HDWP cmdWnds;
    cmdWnds = BeginDeferWindowPos(col.size());
    for (int i = 0; i < col.size(); i++)
        if (i == 0)
            if (DeferWindowPos(cmdWnds, col[i], HWND_NOTOPMOST, x_pos_start_pr + i * x_offset_pr, y_pos_start_pr + i * y_offset_pr, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW) == NULL)
                return ERROR;
            if (DeferWindowPos(cmdWnds, col[i], col[i - 1], x_pos_start_pr + i * x_offset_pr, y_pos_start_pr + i * y_offset_pr, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW) == NULL)
                return ERROR;
    if (EndDeferWindowPos(cmdWnds) == ERROR)
        return ERROR;
    return !ERROR;

where col is collection of cmd windows updated every time this code is run.
After reading Click Here unable to understand how to use it correctly the fucntions.
Does anyone know what is wrong with my code?

Thanks in advance for any help

Datagrid is generated at run time, how to name and write codes for it

Like any other variable/object. You save the reference to it with the appropriate scope and use AddHandler to attach code to events.

Show the code you're using that isn't working. Saying it doesn't work doesn't help to fix it.

I reinterpret guarantee as worst case and actual as on average. So rebalancing of both, insert and delete, is logarithmic in the worst case. On average, insert is constant, even amortized constant. Delete is constant on average, although on every level up there may be a rotation. But the conditions that cause a rotation (i.e. balance factor becoming ±2) diminish all the way up by a factor of < q < 1 [indeed q<½]. So the probability is <1+q+q²+... = 1/(1-q) [indeed <2].

apparently with the column datatype set to numbers, using LIKE isn't possible. You can however use boolean operators with the numbers:

Dim Rows As DataRow() = TempTable.Select("Code > 99999 and Code < 200000")

This will return all rows with code starting with a 1

commented: Thanks +3

see attached

i have solved issue with find string method. but would like to know like method.

Fiestly please show the code what you did.

Secondly, for every catagory at the end the subtotals should be added as a listitem for that catagory. Or you have to create an User Control for your use.

Thank you!

Using your last pastebin, the embedded coder in me tells me that line 12 needs to be either moved or duplicated.

I think I would move that line to after the GPIO.output() statements. Why? Because in one case you didn't declare the GPIO.setup() before you set it high or low so you might send a pulse out that pin. And in another case you may be setting the pin HIGH but since GPIO.setup() was never called it doesn't work.

So my view is on startup, GPIO.setup() those pins and default state so you know what power up condition they should be at and in most systems you don't change GPIO.setup() during a run.

Unfortunately, in this application it still turns all of the GPIO's assigned on or off at the same time. I'm pretty sure it has something to do with the conditions that turn the switches on and off. I'm currently doing all the research possible to find other alternatives or new code. I know its possible as i've seen it before, just not on the coding side of it.

You can cast it so it's not a char pointer, eg cout << (void*) &x

I see, thanks James. So how to get the hexidecimal address of a char variable?

Isn't &var the address of any variable var, regardless its type? (or am I missing something?)

Yes, but you are missing something, namely that the cout << operator for a pointer to a char is overloaded so it works well for char arays (used to hold strings in C). It's a special case. It's defined to treat it as a pointer to a zero-delimited string. The nonsense you see is the ASCII interpretation of whatever bytes are at that address, up to the next zero.

I looked but this is one of those common questions. Should I use a pointer to a single char? I'll write yes. It's not as if you initialized storage and then put the character into that memory location. You are saying "here's a character, now x points at that character." Hence you use the pointer to that string or char.

rprofitt, thanks for the replies, but please look at my original code again, I didn't have any pointer variable, just a char variable x, and then display its adress "&x". Isn't &var the address of any variable var, regardless its type? (or am I missing something?)

To go further we have to think and read more. To me you are setting the pointer's address to that single character so a pointer would be correct.

Thanks for the link to the relevant thread. As for my Line 1, I don't think it's incorrect. I had x as a char type, not a pointer.

Here's an example discussion about this. Another look and it appears your first line 1 is not correct.

char *x='"Test";

You are leaning on your c++ compiler ability to convert a number to ascii. Think back to old C days. Now format it.

As this can be compiler dependent I would not lean on this too hard. Do it like we did in C.

Show an example of the data in the column and the value you're trying to match up.

If I change char to int:

     int x=6;

cout << &x;

The output would be what's expect, an address: 0x28ff0c

I see nothing wrong with it spewing seemingly nonsense. Just like any number you have to convert it to a string somehow.

When I try to display the address of a char type variable, I don't get the normal hexidecimal address, but some strange symbols. I don't have the same problem with int or string, etc.. Example:

  char x='#';
  cout << &x;

The output of this is: #( (

What's the explanation?