Posts by Lucas Lima • 6,714 points
107 posts
-
0
votes4
answers138
viewsA: How to get the last more "+" that appears on the console from this code?
You can solve this problem by not adding + and instead add spaces. Then you make a trim() to remove possible spaces after the value and replace the spaces by +. I did the following here: String…
javaanswered Lucas Lima 6,714 -
12
votes2
answers990
viewsA: How to verify collision between particles?
From the looks of it, the problem is more of a collision check. A way simple, is to check that the distance between the particles is less than the sum of their radii: Something like: dist <…
-
4
votes1
answer468
viewsA: Method does not return correct value
One of the reasons is that in the method somar(int[] valores) there is an infinite loop. You are using i < valores.length as a condition, but forgot to make a i++ after the if. I didn’t…
javaanswered Lucas Lima 6,714 -
9
votes4
answers47343
viewsA: Remove element from an Arraylist in Java
You should look for the object you want to remove before removing it. When you do: Pessoa umaPessoa = new Pessoa(umNome); You are creating a new object that is not in the list and then try to remove…
javaanswered Lucas Lima 6,714 -
3
votes1
answer566
viewsA: Delete file by command line with different type
The command del do not delete read-only files, unless you force it with /f. So, one way to delete all files except the . java is to make the . java read-only and then return them. Read-only: cd…
-
5
votes2
answers1880
viewsA: Variables with Bigdecimal
The problem is that you cannot modify the value BigDecimal, it is immutable. Therefore, you must create a new BigDecimal to store the result, which must be the objective of its variable valorTotal.…
javaanswered Lucas Lima 6,714 -
5
votes2
answers804
viewsA: Why does this code loop infinity?
What is happening is that when you read an invalid value in nextInt() the read buffer remains stored in the Scanner, causing error in next reading, and then, and then, and then ... To solve this,…
-
5
votes3
answers333
viewsA: Is there any advantage in bringing together all the icons of a website in a single image?
This practice of gathering the images into one is called sprite. The advantage is that you save requests to the server. For small sites it doesn’t make much difference, but for large sites, whose…
-
3
votes1
answer2462
viewsA: Call a specific function as you choose from the menu
You can solve this basically with a switch: cout << "\n\nSelecione qual opcao deseja realizar: "; cout << "\n1 - Deposito"; cout << "\n2 - Saque"; cout << "\n3 - Pagamento de…
c++answered Lucas Lima 6,714 -
6
votes2
answers167
viewsA: scanf shows number always as pair
The variable N It’s the whole kind. But on your call from scanf are using "%f" which is for float. Change to "%d" (used for decimal integers) the reading will be done correctly. Give a read on scanf…
-
9
votes4
answers6387
viewsA: How to convert an int to two bytes in C/C++?
You can use union to do this kind of operation. Thus: union Valor { uint32_t dword; struct { uint32_t valor; }; struct { uint16_t word0; uint16_t word1; }; struct { uint8_t byte0; uint8_t byte1;…
-
8
votes4
answers11111
viewsA: Converting float to char array in C/C++
In C, you can do: #include <string.h> #include <stdio.h> int main(){ float valor = 123.456; char convertido[16]; sprintf(convertido, "%.3f", valor); printf("A float convertido = %s",…
-
2
votes1
answer87
viewsA: Qvector to Qimage
You can convert your QVector<QVector<int> > for the PGM format in const char* and let Qt do the rest, because QImage supports PGM. Example: In your case just replace the pgm_file for…
-
0
votes2
answers92
viewsA: How to use Gtkmm-3 and standard input together?
One solution to your problem is to use inter-process communication (CPI). This way, you divide your program into two parts: The first will start the other process (program) that will make the…
-
3
votes2
answers5586
viewsA: How to move, rotate or scale an Object on its local axis in Opengl?
If I understand your question correctly, how do you already perform the calculations using your own class HTransform instead of using classic Opengl functions gltranslatef(), glRotatef() ,…
-
24
votes5
answers20688
viewsQ: How to verify similarity between strings?
It’s very common to compare strings, which is usually done by comparing equality. However, today I have arisen the need to compare the likeness between two strings, so I can compare how similar they…
-
2
votes1
answer190
viewsA: Play in Löve does not work after compiling
From the looks of it, löve just write in the directory %appdata% (in the case of Windows), as in wiki, where you can create a folder for your project. Then, after compiling, the löve apparently no…
-
8
votes2
answers23232
viewsA: How does C/C++ bit offset work?
Bit shift operators "move" all bits of the variable left or right. C C++ has operators: >> Right Shift << Shift to Left For example, moving a variable x to the left: int x = 1; // 0000…
-
12
votes2
answers7627
viewsA: What is the C/C++ volatile modifier for?
A variable volatile indicates to the compiler that the variable can be modified without the knowledge of the main program. Thus, the compiler cannot safely predict whether it can optimize program…
-
8
votes4
answers459
viewsA: What happens when I convert int to char?
whereas a int are 32 bits and a char are 8. In this conversion you will take only the 0 bits up to 7 of your int. If the int storing 1000 is: 0000 0000 0000 0000 0000 0011 1110 1000 // equivale a…
-
3
votes2
answers631
viewsA: Program "jumping" Variables
Your code has 3 errors: Instead of void main(), use int main(). Some compilers may not accept the first form. So it is recommended to use int main(), being the int returns from your program,…
-
1
votes1
answer105
viewsA: Integer to price conversion using Qlocate
This is because you have removed the ',' and the '.' to make an integer. But when you go to print the final amount you do not return with the part of the cents and conversion believes it is 103,083…
-
6
votes2
answers2104
viewsA: How to add R7 portal bar on site?
Basically, like this: <html> <div style=" position:fixed;top:0;left:0;width:100%;"> <script type="text/javascript" src="http://barra.r7.com/bariso.js"></script> </div>…
-
0
votes1
answer69
viewsA: Update a Tableview
You can run a setModel() back to the TableView, right after closing the Dialog: // ... model->select(); ui->tableView1->setModel(model); Assuming the name of your TableView be it…
-
9
votes3
answers5076
viewsA: How to pick up the arrow keys in C/C++?
In pure C/C++ you can’t do that. To handle directional keys you must work with a specific API. You can do this by using the Windows API (Win32), SDL2, SFML, Allegro, Ogre3d, GTK, Qt, wxWidgets etc,…
-
5
votes2
answers12416
viewsA: Resize image with PHP while maintaining aspect ratio
You can use the Wideimage to resize the image. For example: $path = $_GET['img']; // faça as verificações de validade da imagem... $image = WideImage::load($path); // scala: $width = $_GET['width'];…
-
0
votes2
answers461
viewsA: QMYSQL driver not Loaded Qtcreator
Make sure the mysql library is in a location accessible to Qt (/usr/lib/, /usr/lib/i386-linux-gnu or something like). As you said you have already installed mysql, you should find the following…
-
3
votes3
answers22495
viewsA: How do I start Tomcat as a service on Linux?
You can run this script in /etc/rc.local. This file runs right after boot. The format should look something like this: # # rc.local # # This script is executed at the end of each multiuser runlevel.…
-
6
votes3
answers1655
viewsA: How to verify which technologies the CPU supports at runtime?
Just to add the @Guilherme Bernal reply and share the code. I made a program to test the class that William posted and it looks like working. I haven’t fully tested yet as this varies from PC to PC.…
-
13
votes2
answers2414
viewsQ: #pragma Once or #ifndef?
I know there are two ways to prevent a header file from being duplicated in C C++: #ifndef FOO_H_INCLUDED #define FOO_H_INCLUDED class Foo { // código }; #endif And #pragma once class Foo { //…
-
6
votes3
answers949
viewsA: How does the Xor Swap algorithm work?
It is used to exchange two values without the need for a temporary variable, using operations xor. To understand it is only to look at the table of xor and analyze step-by-step the algorithm: To x =…
-
6
votes3
answers1655
viewsQ: How to verify which technologies the CPU supports at runtime?
I am writing a program for PC that has optimized function calls for SSE2, SSE3 and maybe SSE4. However, I cannot guarantee that the PC running the program supports these technologies and would like…
-
8
votes3
answers2325
viewsA: How does the rotation of Bits in C work?
The bit rotation is similar to the bit displacement process. Only, in this case, you don’t "lose" the bits that extrapolate the dimension of your variable (the most significant or the least…
canswered Lucas Lima 6,714 -
1
votes1
answer442
viewsA: Class creation in C++
The location where you define the class will basically influence access to the definitions by other snippets of code, because for the compiler this won’t make much difference. However, you should…
-
1
votes3
answers869
viewsA: Time measurement in Windows
For Windows specifically, the best way (in the sense of having higher resolution) is to use the QueryPerformanceCounter. An example of usage (use a recent compiler): #include <windows.h>…
-
14
votes6
answers11304
viewsQ: How to get distance given the coordinates using SQL?
I’m doing a function in php, in which, given a GPS coordinate, it will search in the database the recorded locations, which are not necessarily fixed, within a certain distance. My question is, how…
-
10
votes2
answers455
viewsQ: What is the best alternative: define, enums or variables?
Recently, in a project where I have to declare many counts, I came to this doubt. Which is the best option define's, enum's or constant variables? At first I think to use enum is the best…
c++asked Lucas Lima 6,714 -
7
votes5
answers9524
viewsA: Receive an expression and calculate in C
There is no function eval() standard in C. The solution to your problem is to look for a library that already does the same as the eval() does or develops on its own a function that interprets the…
-
3
votes2
answers1084
viewsA: How to write a string in a stream using physical files?
The problem is that the scanf("%s",str); reads the string and ignores whitespace. A solution to this is " %[^\n]", instead of %s, which will read the entire line written by the user until it finds a…
canswered Lucas Lima 6,714 -
4
votes1
answer178
viewsA: Error #1009 after first run
I don’t know exactly how you’re structuring your project, but by the looks of it you’re not using the concept of Flash Objects well. The ideal is that you define a class that presents the object.…
actionscript-3answered Lucas Lima 6,714 -
4
votes2
answers159
viewsA: div stops being updated in IE11
I managed to solve the problem. As discussed in the comments of the question, the cause of the problem was that EI stopped requesting server information and started using the cached information. As…
-
4
votes2
answers159
viewsQ: div stops being updated in IE11
In a project I am developing I need to update some page fields each 50ms (this is adjustable). The problem is that when I test in IE, the fields are no longer updated overnight, with no explanation…
-
4
votes3
answers671
viewsA: A C program can tell which OS it is compiling?
Typically cross-platform Apis develop code specifically for each platform and do not check has run time. The code is only specified at compile time for a target platform. For this, they usually…
-
3
votes1
answer189
viewsA: How to create a file open dialog with the SDL library?
You can install the GTK+ (is also in C) and use it to show a File Chooser Dialog, where the user will select the music file. From there on you can do with the SDL even. Some references: GTK Getting…
-
7
votes2
answers2496
viewsA: How to know when the user opened an application?
One solution is to check the processes that are open in a thread and find out which application you are checking for. A very simple example to check when the user opened the Windows calculator…
-
1
votes4
answers4937
viewsA: Generate string securely random in PHP
There are several ways to generate "random" strings, and generally the key issue in algorithms is the Seed which will be the source of the entropy and the algorithm that will generate the random…
-
3
votes3
answers3981
viewsQ: Problem with Hover in CSS
I have a table and I want each cell to be highlighted when the mouse is over. However, it is not working. It should be considered that I am using bootstrap as a basis for page styles and therefore I…
-
6
votes2
answers8421
viewsA: How to run Android projects, on Eclipse, on a smartphone?
Try the following: Enable USB Debugging on your smartphone. Install its driver on PC (some only work like this). If you have to install driver, restart Eclipse. To make sure the SDK is detecting the…
-
2
votes2
answers5688
viewsA: Object Comparison
You are not forgetting to specialize in the equals for Produto? Must be something like: @Override public boolean equals(Object other) { if (other == null) return false; if (other == this) return…
-
17
votes7
answers78990
viewsA: How does this if/Else work with "?" and ":"?
This form of if-lse is known as ternary conditional operator. It is common in several languages, not only for javascript. The advantage of this format is that you make an if-lse on a line and form…