|
Don't know what to tell you, showing code is far better than trying to describe it. No one has criticized your coding 'style', they've mentioned things that are logical improvements, not code style improvements. Make the smallest runnable example that exhibits the problem, then show the whole example.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Here is a working , sanitized / abbreviated TEST code used in method
information_main.count() = 2
{
QList<QBluetoothHostInfo> information_main = QBluetoothLocalDevice::allDevices();
int index = 0;
do
{
information_main.at(index).address().toString();
index++;
} while( index != information_main.count() );
reset index and run it again - works as expected
fails run time if index is not reset - as expected
index = 0;
do
{
information_main.at(index).address().toString();
index++;
} while( index != information_main.count() );
|
|
|
|
|
What is this? Can't you post the whole class definition, initialization, and the method you mentioned?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
What does this have to do with the problem? You were asked to create a sample that demonstrates the problem you are having. This merely demonstrates that correct management of the index variable makes the code work.
|
|
|
|
|
Hi . Recently i've got to make a game called gomoku between two players . Now i need to edit it and change it from PVP to versus computer . I understand that in order of getting a random number from computer i can use <time.h> and rand() , and the letter by something like this :
char letters[] = "abcdefghijklmnopqrstuvwxyz";
char x = letters[rand() % 26];
Now my question is how i can add it in my program , i tried to put them in but it still is not generating a move from computer . Here's my code,maybe u have some ideas
#include <iostream>
#include <iomanip>
using namespace std;
void print_table(int x[][15]) {
system("cls");
for (int i = 0; i < 15; i++) {//the loop that use to print out the english character row
if (i == 0)
cout << setw(4) << "A";
else if (i == 1)
cout << " B";
else if (i == 2)
cout << " C";
else if (i == 3)
cout << " D";
else if (i == 4)
cout << " E";
else if (i == 5)
cout << " F";
else if (i == 6)
cout << " G";
else if (i == 7)
cout << " H";
else if (i == 8)
cout << " I";
else if (i == 9)
cout << " J";
else if (i == 10)
cout << " K";
else if (i == 11)
cout << " L";
else if (i == 12)
cout << " M";
else if (i == 13)
cout << " N";
else if (i == 14)
cout << " O";
else if (i == 15)
cout << " P";
}
cout << endl;
for (int i = 0; i < 15; i++) {
cout << setw(2) << i;//print out the row number
for (int j = 0; j < 15; j++) {//print out the board game.
if (x[i][j] == 0) {//the inital value is 0, so when the block is 0 then print out the '.'
cout << " .";
}
else if (x[i][j] == 1) {//when the player O input the block then the value will adding one then if check the block is one then output the 'o'
cout << " O";
}
else if (x[i][j] == 2) {//when the player X input the block then the value will adding two then if check the block is two then output the 'x'
cout << " X";
}
}
cout << endl;
}
}
int check_player(int p) {
if (p == 1) {//change the player everytime before the next loop compile
p++;
}
else {
p--;
}
return p;
}
void input_value(int &t, int &n, int p, int x[][15]) {
char eng;
int number;
do {//the loop that ask for the user input the location.
cout << "player ";
if (p == 1) {
cout << "O";
}
else {
cout << "X";
}
cout << ", make a move: ";
cin >> eng;//input the location
cin >> number;
if (eng == 'A')//change the character to different number
t = 0;
else if (eng == 'B')
t = 1;
else if (eng == 'C')
t = 2;
else if (eng == 'D')
t = 3;
else if (eng == 'E')
t = 4;
else if (eng == 'F')
t = 5;
else if (eng == 'G')
t = 6;
else if (eng == 'H')
t = 7;
else if (eng == 'I')
t = 8;
else if (eng == 'J')
t = 9;
else if (eng == 'K')
t = 10;
else if (eng == 'L')
t = 11;
else if (eng == 'M')
t = 12;
else if (eng == 'N')
t = 13;
else if (eng == 'O')
t = 14;
if (!(eng >= 'A'&&eng <= 'M') || !(number >= 0 && number <= 14) || x[number][t] != 0) {//when the input wrong, output the statement to ask anouther input and loop again.
cout << "Invaid input, Try again!" << endl;
continue;
}
else {//if no problem then this input loop is break and jump to the next statement
break;
}
} while (1);//Because it will break as well so the do-while loop is no any requirement
n = number;
}
int main() {
const int num = 15;//the number for constant the array row and column value
char check_e;//for the user input the column
int R[num][num] = { 0 }, check_n, player = 1, buger = 0, transfer, playerO_win = 0, playerX_win = 0, draw = 0, check_draw;//the variable that for user input or checking the game statment
do {//launch the loop for the user input again and again
check_draw = 0;//reset the checking of draw
print_table(R);
input_value(transfer, check_n, player, R);
R[check_n][transfer] += player;//change the value according the player's input and the player name.
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
if (i <= 8 && R[j][i] != 0 && (R[j][i] == R[j][i + 1] && R[j][i] == R[j][i + +2] && R[j][i] == R[j][i + 3] && R[j][i] == R[j][i + 4])) {//the checking for the row bingo
if (R[j][i] == 1) {
playerO_win++;
break;
}
else {
playerX_win++;
break;
}
}
else if (j <= 8 && R[j][i] != 0 && (R[j][i] == R[j + 1][i] && R[j][i] == R[j + 2][i] && R[j][i] == R[j + 3][i] && R[j][i] == R[j + 4][i])) {//the checking for the column bingo
if (R[j][i] == 1) {
playerO_win++;
break;
}
else {
playerX_win++;
break;
}
}
else if (j <= 8 && i <= 8 && R[j][i] != 0 && (R[j][i] == R[j + 1][i + 1] && R[j][i] == R[j + 2][i + 2] && R[j][i] == R[j + 3][i + 3] && R[j][i] == R[j + 4][i + 4])) {//the checking for the \ situation.
if (R[j][i] == 1) {
playerO_win++;
break;
}
else {
playerX_win++;
break;
}
}
else if ((j >= 4 || i >= 4 || i <= 8) && R[j][i] != 0 && (R[j][i] == R[j - 1][i + 1] && R[j][i] == R[j - 2][i + 2] && R[j][i] == R[j - 3][i + 3] && R[j][i] == R[j - 4][i + 4])) {//the checking for the / situation
if (R[j][i] == 1) {
playerO_win++;
break;
}
else {
playerX_win++;
break;
}
}
for (int i = 0; i < num; i++) {//the loop for checking the draw
for (int j = 0; j < num; j++) {//this loop will check for every time compilation.
if (R[j][i] == 0)//when there are any empty block then the check_draw will adding, the draw situation is the check_draw be 0
check_draw++;
}
}
if (check_draw == 0) {//when the check_draw equal to 0 which mean the situation is no empty block
draw++;
break;
}
}
if (playerO_win != 0 || playerX_win != 0 || draw == 1)//break the second loop
break;
}
if (playerO_win == 1 && playerX_win == 0) {// when the player win print the block game again and print out the win statement
print_table(R);
cout << "player O wins!" << endl;
break;
}
else if (playerX_win == 1 && playerO_win == 0) {//the other player win the game
print_table(R);
cout << "player X wins!" << endl;
break;
}
else if (draw == 1) {//the draw block game print
print_table(R);
cout << "Draw game!" << endl;
break;
}
player = check_player(player);
} while (1);//in fact it is no need for the loop statement, because most of the situation will have a break statement for out of the loop
return 0;
}
modified 22-Nov-20 9:41am.
|
|
|
|
|
You need to learn how to use a debugger to find your problem. It will allow you to step through your code, one line at a time, to find out where it's doing something unexpected.
I will point out, however, that you can map a char to a range that starts at 0 like this:
t = eng - 'A';
'A' through 'Z' have contiguous values, so this maps eng to 0 to 25 , assuming that it was an uppercase letter. You can check for invalid input with
if((t < 0) || (t > 14))... // or t > ('O' - 'A')
Similarly, you can write
cout << ' ' << i + 'A';
|
|
|
|
|
I hope I'm in the right spot to ask this programming question. I'm looking for the "C" programming spec's that is equivalent to which the users invokes the windows 10 run dialog box by keystrokes. I like to see the option on my windows sidebar to click on. Is there a place(website) out on the internet that shows the ideas and some spec's and examples on how to put this simple programming idea, in "C", together. Any help sure be appreciated. Thanks,
|
|
|
|
|
Hi,
samtoad wrote: equivalent to which the users invokes the windows 10 run dialog box It's an undocumented function located in shell32.dll at ordinal 61. I think the function is named RunFileDlg if I remember correctly.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: ...in shell32.dll at ordinal 61. You're showing your age there, David. Looking at ordinal numbers inside of Windows DLLs is going back aways. Those were the good ol' days.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
David Crow wrote: You're showing your age I hope that I have a few more years left in this worn out body.
David Crow wrote: Looking at ordinal numbers inside of Windows DLLs is going back aways. Those were the good ol' days.
There isn't a more accurate way to describe that particular DLL export. It's exported from shell32 with the NONAME attribute.
D:\Tools>dumpbin /exports "C:\Windows\System32\shell32.dll"
...
61 00102C60 [NONAME]
... In fact it looks like there are 355 additional exports in shell32 that are NONAME (only exported by ordinal)
Best Wishes,
-David Delaune
|
|
|
|
|
What are you actually trying to do? Do you just want to run this dialog, or start some other process?
|
|
|
|
|
Richard, all I want to do is just what windows 10 does, but access from the sidebar, instead of
windows + R. Is there a programming way of doing it?? Thanks.
|
|
|
|
|
Access the Run dialog from the sidebar? What is the sidebar?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Run the command line: rundll32 shell32.dll,#61
|
|
|
|
|
|
Problem c++
Hi i have an txt-file that looks like this:
Bigman arnold :line1
1333131313131 :line2
blue 123 green 2, 234 green :line3
arctic 34 :line4
The thing i have to do is modify the out put from the txt file.
There are many more lines.
I have to modify it so the output from the files so it becomes like this:
arnold Bigman :line1
blue 123 green 2, 234 green :line 2
arctic 34 :line3
1333131313131 :line4
And the lines continues for the rest of the txt file.
I'we been trying ifstream with a while(file>>string1>>string2>>getline(zzzzz, file)
But i get an error im totally of.
Sometimes there are only 3 lines for the adress and sometimes 4.
Any good ideas?
|
|
|
|
|
So are you needing to know how to read from one file and write to another, how to swap strings, or something else? I see no pattern in your input/output (e.g., line 1 swaps the two words, line 2 moves to line 4).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
begzz wrote: But i get an error We cannot guess what error you get. Please edit your question, show the actual code you are using, the error that you get and where in the code it occurs.
|
|
|
|
|
PS C:\Users\anubi\Desktop> cd "c:\Users\anubi\Desktop\" ; if ($?) { g++ Tryout1.cpp -o Tryout1 }
; if ($?) { .\Tryout1 }
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot open output file Tryout1.exe: Permission denied
collect2.exe: error: ld returne
I can't even run a simple program to print "hello". I installed MinGW and setup the path. What is mising in VSC?
|
|
|
|
|
The message is clear. Either you do not have permission to write into that location, or the file is in use by some other process.
|
|
|
|
|
The most common cause of that error is the executable your trying to compile is already running, probably from a previous launch of the app you never closed.
|
|
|
|
|
In C, I need to code the next 10 prime numbers of n entered from the keyboard with an array. How do I do it?
|
|
|
|
|
|
iHuy wrote: How do I do it? Can you do it on paper? If not, then trying to code such an algorithm is not going to work (unless someone just outright gives you the code).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I know Borland turbo IDE had a compiler that supported multiple multiple inheritance in C++. I want to know is there any other compiler that does that or was that it?
|
|
|
|