Latest Software Development Posts

Sets the colors for the specified display elements. Display elements are the various parts of a window and the display that appear on the system display screen.

Write a function that computes the alternating sum of all elements in an array. For example, if alternating_sum is called with an array containing
1 4 9 16 9 7 4 9 11
then it computes
1 – 4 + 9 – 16 + 9 – 7 + 4 – 9 + 11 = –2

It seems to get stuck when I try to quit the inputs. If understands then please let me know.

How do I create a socket server and start receiving clients, if my main thread is processing UI messages?

I tried putting all of the server code in a thread using CreateThread() from WinMain(), but it just crashes with an error:

LearnCpp.com is a free website devoted to teaching you how to program in C++. Whether you’ve had any prior programming experience or not, the tutorials on this site will walk you through all the steps to write, compile, and debug your C++ programs, all with plenty of examples.

Becoming an expert won’t happen overnight, but with a little patience, you’ll get there. And LearnCpp.com will show you the way.

Hi,

I have few QActions added to a QMenu:
ui->menuView->addAction( pAction1 );
ui->menuView->addAction( pAction2 );
ui->menuView->addAction( pAction3 );

My problem is that I can't disable a particular QAction:
pAction2->setDiasbled( true ); // doesn't do anything

In the documentation it is written: "An action will be disabled when all widgets to which it is added (with QWidget::addAction()) are disabled or not visible."
So why it doesn't work makes sense, but it is not what I want.

How can I do it?

Thanks.

@
QMenuBar menuBar;
QMenu
menuFile;
QAction actionOpen;
QAction
actionClose;

menuBar = new QMenuBar(MainWindow);

menuFile = new QMenu(menuBar);
menuFile->setTitle("File");

actionOpen = new QAction(MainWindow);
actionOpen->setText("Open");

actionClose = new QAction(MainWindow);
actionClose->setText("Close");

menuBar->addAction(menuFile->menuAction());
menuFile->addAction(actionOpen);
menuFile->addAction(actionClose);
@

To disable one of the items or whole "File" menu
@
actionOpen->setEnable(false);
menuFile->setEnable(false);
@

To enable them back
@
actionOpen->setEnable(true);
menuFile->setEnable(true);
@

Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        Me.Validate()
        DataGridView1.EndEdit()
        da.Update(dt)
        MsgBox("Data Updated!!")
        Me.BindGrid()
    End Sub

The problem with the execution of dank = dankestmemes(); at line 54 is that it is only executed if option is not Y/y. The continue at line 50 when option = Y/y sends the program to check the while condition at line 58, bypassing line 54.

It depends on when the correct value for var3 is known and by whom (i.e. which function). If it is known only by func14, there's no point in changing the code. If it is known before the cascade of functions is called you might make it global. Since you have not stated which language you're using let's assume its c. If you declare var3 outside all functions, it will be visible inside each one including func15.
See: https://www.codingunit.com/c-tutorial-functions-and-global-local-variables

His code looks like mine. Haha

I don't know why you were getting the error. when I move line 13 like I said, it compiles just fine.

There is another problem however, you're not consuming the end of line character in your scanf or flushing the standard input. This creates problems when scanf runs again it reads the end of line character and the program ends. Something like this would work on Windows:

printf("Want go again? Y/N: "); // asks if user wants to go again
char temp = '\0';
scanf("%c%c", &option, &temp); // executes input

While looking at your program, it became obvious to me that using enum constants and hard coded descriptions, can be a maintenance nightmare down the road if you decide to add or remove a tribe. A struct with members name and description can be used in an array to simplify your code and be much easier to maintain:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define NUMBER_OF_TRIBES 5
struct tribe
{
    char name[20];
    char description[200];
};
int dankestmemes(void); // function prototype
struct tribe tribes[NUMBER_OF_TRIBES];
int main(void) {
    srand(time(NULL)); // randomize random generator using current time
    tribes[0] = (struct tribe) 
    { 
        .name = "YEE", 
        .description = "You belong to the tribe of Yee. Where the most obnoxious beings reside. Here you  \nwill endure endless singing.\n" 
    };
    tribes[1] = (struct tribe)
    { 
        .name = "KNUCKLES", 
        .description = "You belong to the tribe of Ugandan Knuckles. Welcome my brutha, here you will find those \nwho are adventurous. We strive to find our queen and ...

If the functions are in a class you declare it as a member of that class. If it is meant only for internal use keep it private, if a user of the class will need it make it public.

How do you make a variable global to a scope? I only know about global variables to an entire program where you put it at the top of the program then your entire program can see it.

i solve it :) by this
i tried to check the result list or not

if isinstance(query.getvalue("Checkbox1"), list):
                for i in query.getvalue("Checkbox1"):
                        print i
else:
                print query.getvalue("Checkbox1")

I see this example made by Tkinter
i want do that with native python not any framework or toolkit

this is my example
html code :

<form method="post" action="bb.py">
<input type="hidden" name="do" value="ss" size="20">
        <input name="Checkbox1" value="111" type="checkbox" />aa1<br />
        <input name="Checkbox1" value="112" type="checkbox" />aa2<br />
        <input name="Checkbox1" value="113" type="checkbox" />aa3<br />
        <input name="Checkbox1" value="114" type="checkbox" />aa4<br />
        <input name="Checkbox1" value="115" type="checkbox" />aa5<br />
        <input name="Submit1" type="submit" value="submit" /><br />
</form>

python code

for i in query.getvalue("Checkbox1"):
      print i

if i checked one box the result will be spaces
1 1 1
if i checked 2 box the result will be work
111 112

how can fix it ?

Hello,
I created html file with Checkbox and i use python
when i check one box and submit i have problem with list

when i check 2 box or more and submit i see the result list like
['120', '104', '12']
i can use "for" to loop the list and do action
but when i check one box i see the result withour list like
120
not ['120']

whe i use for it the loop will be 1 , 2, 0

how can i fix this
Thanks

I've seen the following code for binding the Escape Key to a Tkinter GUI:

import Tkinter as tk

def exit():
    root.destroy()

root = tk.Tk()
root.bind("<Escape>", exit)
root.mainloop()

However, when I add this to my GUI program, I don't get a response when Esc key is pressed. It does nothing. Any suggestions?

If all the functions are in the same scope, use a variable that is global to that scope, and only moduify the arguments for and the calls to func15. Most modern IDE's will make that relatively easy.

I have 30 functions like this

void func1(int *var1, int *var2)
{
    func2(var1, var2);
}

void func2(int *var1, int *var2)
{
    func3(var1, var2);
}

void func3(int *var1, int *var2)
{
    func4(var1, var2);
}

I do not need var3 until func15. Is there a way to fix this mistake without having to change all the function calls and headings? var3 needs to be remembered every time I get to func15. I only use var3 in func15 though so I really do not want to have to change all of my function calls and headings. It obviously can't be a local variable or it will be forgotten each time it is called.

void func15(int *var1, int *var2, int *var3)
{
    func16(var1, var2);
}

t = int(input())
for _ in range(t):
n,k = map(int,input().split())
li = list(map(int,input().split()))
li.sort(reverse=True)
j = 0
while k+j-1<n and li[k-1]==li[k-1+j]:
    j = j+1
print(k+j-1)

You have correctly been told twice by different people about moving the dank assignment to insode the loop, but you haven't moved it.

A friend told me to do something like add the dank = dankestmemes() part after the if statement so it updates the variable when it loops around it'll produce a different result. But I'm still getting the same output.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

enum meme {YEE, KNUCKLES, DOGE, HARAMBE, BUTKUS};

int dankestmemes(void); // function prototype

int main(void) {   

    srand(time(NULL)); // randomize random generator using current time
    enum meme dankMeme; // can contain YEE, WAE, DOGE, HARAMBE, or BUTKUS   
    int dank = dankestmemes(); // When program first executes
    char option;

    do{
        switch(dank){     
            case 0: // You will be put in the Yee dinosaur tribe
                dankMeme = YEE;  // Possibly the greatest meme in existance
                printf("You belong to the tribe of Yee. Where the most obnoxious beings reside. Here you  \n"); // I recommend watching the YouTube video
                printf("well endure endless singing.\n"); // https://www.youtube.com/watch?v=q6EoRBvdVPQ
                break;        

            case 1: // You will be put in the Ugandan Knuckles tribe
                dankMeme = KNUCKLES; // #EBOLA
                printf("You belong to the tribe of Ugandan Knuckles. Welcome my brutha, here you will find those \n");
                printf("who are adventurous. We strive to find our queen and da wae.\n"); 
                break;

            case 2: // u will b put in tribe of Doge
                dankMeme = DOGE;
                printf("U BELONG 2 THE TRIBE OF DOGE. MUCH WOW VERY AMAZE!!\n");
                break;

            case 3: // You will be put in the tribe of Harambe
                dankMeme = HARAMBE; // RIP in Peace sweet prince 
                printf("You belong to the tribe of Harambe! Here you will feel ...

It gives me this:

warning: implicit declaration of function ‘dankestmemes’ [-Wimplicit-function-declaration]
     int dank = dankestmemes(); // When program first executes

Try this, put line 13 int dank = dankestmemes(); after line 16 do{.

Let me ask a question about line 10. When I see the value 0, did you want the character 0 or null or did you want a zero as in '0'?

I did the
while(option != 'y' && option != 'Y');

thing and this is the output:

You belong to the tribe of Harambe! Here you will feel the presence of his amazing grace. Only the wise and strong reside in this tribe.
No wonder why this tribe is everyone's favorite.
Want to be resorted? Y/N: Y

and then it just goes back to bash from there. What confuses me is that it wants to work, but it isn't randomizing the outcomes :/

I edited my response a few times so make sure you look at it again to make sure you got the (hopefully) error-free version.

I just looked at the code and I just realized, that somehow I got to implement it inside the int dankestmemes(void) function or make a function prototype that allows you to play again but I'm not sure, because it doesn't seem to randomize at all, but I'll try what you said.