Posts by Guilherme Bernal • 20,024 points
220 posts
-
1
votes1
answer653
viewsA: How to extract hexadecimal code from a nasm-compiled executable?
The language or compiler you used little influences the format of the final executable. If you are on Linux, it is very likely to be a ELF (Executable and Linkable Format). Already in Windows, will…
-
15
votes2
answers298
viewsQ: Does the syntax '//' have any special meaning?
I was using Notepad++ (v 6.5) to write a javascript file when I noticed the following: I wrote a comment line starting with ///, three instead of the usual two. When running this line seems to be…
-
12
votes5
answers17141
viewsA: Ignore CSS on a particular page snippet
How about using a :not to ignore a specific class? Something like that: #foo input:not(.ignoreCss) { background: red; } <div id=foo> <input></input> <input></input>…
-
4
votes1
answer1343
viewsA: How to make a vertical bar graph with the c+# character?
If I understand correctly, you want to draw N bars each with height Hk. As the output is horizontal you have to go drawing a piece of each bar at a time before skipping the line. Then first find the…
-
4
votes1
answer33086
viewsA: id returned 1 Exit status C code, help
I have compiled your code on my machine and the error message is quite clear: /tmp/ccaHCVvZ.o: In function `main': a.c:(.text+0x13): undefined reference to `Printf' collect2: error: ld returned 1…
canswered Guilherme Bernal 20,024 -
2
votes3
answers5051
viewsA: Include link in a container
For this the simplest way is to use javascript in the onclick event of div: <div style="cursor: hand;" onclick="location.href='www.google.com'"> Qualquer coisa aqui </div> The problem…
-
1
votes1
answer63
viewsA: Update a Combobox after opening Qdialog
From what I understand you need the function carregar_comboBox() always be called before the dialog is shown on the screen. A simple solution is to re-implement the function show() overwriting the…
-
5
votes1
answer155
viewsA: Check if an element exists with switch
The definition of the function is quite confusing. I believe you want to do the following: function forumversion() { if (jQuery('#ipbwrapper').length) return "invision"; if…
-
4
votes4
answers6797
viewsA: Creating a JS bot
Using javascript running within the context of a page (and limited by the browser sandbox) it is not possible to manipulate documents coming from another domain, either in a new window or in an…
javascriptanswered Guilherme Bernal 20,024 -
0
votes5
answers1352
viewsA: Previous "Else" without "if" error
Several errors in sequence in your code. Let’s go one by one: if (a = 0) Here you are assigning zero to a, then checking if this value is true (zero is false). Then you overwrite the original value…
canswered Guilherme Bernal 20,024 -
4
votes3
answers238
viewsA: How to stop three loopings for in C
By seeing a function with so many levels of identation one within another the first thing that comes to mind is: this function is doing too much. In an ideal environment, each function should have a…
-
2
votes2
answers315
viewsA: Why are you giving Segmentation fault in my Assembly inline?
First a little theory: The memory is divided into pages, each with different access permissions. At the very beginning of the process the code is loaded into a readable and executable (but not…
-
1
votes2
answers307
viewsA: End of Java Scanner input
You can use the class documentation to understand the methods it has: Scanner. Follow a simple example (untested): import java.util.Scanner; public class SimpleScanner { public static void…
-
3
votes3
answers694
viewsA: Using function and header file (header)
The problem is merely that you have compiled only one file, the MainCodeCount.c and left the CodeCount.c from outside. So there is no one defining the function the function imprime() in the linking…
canswered Guilherme Bernal 20,024 -
6
votes4
answers1095
viewsA: Why can’t I release memory?
First of all, delete releases the memory pointed by the pointer, but does not touch the pointer itself. It will continue to point to where the data was before. Analyzing your code we have to A will…
-
3
votes1
answer335
viewsA: How to make a Sorting in classes?
The good way to implement this is to make your class comparable, implement the operator<. Thus: bool Person::operator<(const Person& other) { return num_ < other.num_; } Now you can…
-
3
votes1
answer185
viewsQ: Why explicitly declare the base when calling function when using templates?
I have the following code: A derivative template calling a base function also template. template <int M> struct Base { void foo() {} }; template <int M> struct Derived : public…
-
1
votes1
answer95
viewsA: gcov tests code coverage during build or run?
gcov works by using instrumentalization of the code. For example: to check which functions are called, it adds code at the beginning of all functions to save the name of the function itself in a…
canswered Guilherme Bernal 20,024 -
6
votes2
answers107
viewsA: Simple calculation between string and integer
It is a feature of the language, Javascript is Weakly typed. You can check the type of your variables is actually a number before proceeding, if you want: if (typeof(asd) == "number") novo = asd /…
-
2
votes4
answers9544
viewsA: How to display parts of a page only after loading the entire content of the site?
You can put what you don’t want visible in an element with display: none; and, at an opportune moment, as in body.onload, make it visible. <div id="hiddenDiv" style="display: none;"> <!--…
javascriptanswered Guilherme Bernal 20,024 -
2
votes4
answers459
viewsA: What happens when I convert int to char?
Explicitly referring to the C standard (I used N 6 Language 6.3 Conversions 6.3.1 Arithmetic operands 6.3.1.3 Signed and unsigned integers 1 When a value with integer type is converted to Another…
-
10
votes4
answers8703
viewsA: Programming Online in C?
There should be a list of compilers online on the tag wiki C and C++. In general the sites that accept C++ must also accept C. Here some: Coliru Ideone Codepad Rextester…
canswered Guilherme Bernal 20,024 -
3
votes3
answers457
viewsA: Lock the window zoom
In the builder you can do the following: setFixedSize(size()); Or still to use recommended size instead of standard: setFixedSize(sizeHint()); So the maximum and minimum window size will be set to…
-
14
votes2
answers2414
viewsA: #pragma Once or #ifndef?
The big difference is that the Guards header (#ifndef) use a standard feature and are supported by any and all conforming compiler. Already a #pragma behavior dependent on each compiler. It is the…
-
3
votes3
answers1655
viewsA: How to verify which technologies the CPU supports at runtime?
The ideal is to use CPUID as you suggested. It is an instruction of the x86 architecture that will return everything that the current CPU supports. To use this you need to use _cpuid() on Windows or…
-
3
votes1
answer196
viewsA: How to validate the price in Qt?
If you want to validate precisely a number in the format of a price (exactly two decimal places, without being in exponential format, comma separator, thousands point separator), you should use…
-
15
votes6
answers35893
viewsA: Keyboard buffer cleaning after scanf
The problem is that when you type the following: A [enter] B [enter] The following has been inserted into the input buffer: A\nB\n When performing scanf("%c", &c) you read a single character…
-
5
votes2
answers259
viewsA: Removal of repeated values
Recital C++11, the following is valid: vector<pair<int, int>> vec1 = {{10, 2}, {10, 1}, {3, 7}}; vector<pair<int, int>> vec2 = {{1, 3}, {9, 10}}; To invert the coordinates of…
-
7
votes2
answers156
viewsA: Problem with Math. h functions
The calculation is correct, your problem is just in time to display the value on the screen. When compiling the code I have the following Warning: a.c: In Function main: a.c:22:4: Warning: format %f…
canswered Guilherme Bernal 20,024 -
10
votes2
answers4823
viewsA: How to access a specific RAM location by address?
To begin, strictly speaking, you can only write and read data from valid pointers, i.e., pointers created from objects within your lives. A pointer to any other place is invalid and cannot be read…
-
3
votes1
answer227
viewsA: Best way to return data entered by a select of constants
Instead of turning the list into a hash you can do the search directly using the method find. Thus: def tipo_tos tipos.find {|t| t[1] == tipo}[0] end But perhaps the most interesting thing is to…
-
176
votes6
answers5796
viewsA: How is computer randomization generated?
The only really random thing are quantum effects, such as radioactive decay (which of the nuclei will break down now?). And that’s kind of tricky to get on home computers. Several of these…
-
4
votes2
answers1632
viewsA: Regex to pick numbers between the second and third "/"
If it’s always product, you can do: /produto/(\d+)/ (regexplained) If prefix changes depending on case use: /(\w+)/(\d+)/ (regexplained) Note that I also captured the prefix in this case. Depending…
-
4
votes2
answers3447
viewsA: PDF view in browser
Usually browsers are able to render PDF, so the simplest way is to forward the user directly to the pdf with a simple link or still using a <iframe>. If the browser cannot render, the file…
-
4
votes1
answer819
viewsA: How to Connect/Disconnect wi-fi on Android?
You can use the class WifiManager for this, in particular the function setWifiEnabled. Example (within an Activity): WifiManager wifi = (WifiManager)this.getSystemService(Context.WIFI_SERVICE)…
androidanswered Guilherme Bernal 20,024 -
7
votes4
answers6417
viewsA: How to split a string into C++?
It is interesting to note that often stdlib already has very similar algorithms that can be used for its purposes. If the delimiter is always the space, you can rely on reading strings from streams.…
-
10
votes1
answer4778
viewsA: How to read content from a Javascript site?
You can directly make an AJAX request to the server, like this: xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status ==…
-
2
votes1
answer1403
viewsA: Chained lists - add at the end of the list
The problem is trying to insert something at the end of an empty list. In this case both the auxiliar as to the anterior are NULL. The crash will happen while doing anterior->prox =…
canswered Guilherme Bernal 20,024 -
4
votes3
answers579
viewsA: Delete . bashrc, . bash_profile and . profile files: what are the consequences?
These files are part of the system and serve to set a configuration to the terminal when you open it. RVM changes them to include in the PATH and can be executed directly even if it is in your home.…
-
16
votes5
answers61683
viewsA: Using line break " n" in Java
Not all platform uses "\n" as line separator. Example: Linux: "\n" Windows: "\r\n" Some Macs: "\r" So one way to know which line separator of the current platform is as follows:…
javaanswered Guilherme Bernal 20,024 -
2
votes2
answers355
viewsA: Maximize Solution: Sublist Construction Meeting Limit
You have a set of items and that form a subset whose sum is less than X, so that it has the largest possible sum and has the largest possible number of items. This problem is quite similar to…
-
7
votes3
answers150
viewsA: Crash after reading value with scanf
I suppose you meant to say scanf ("%d", &sal); in place of scanf ("%d, &sal"); The first one says, "Read a number and put it in the variable sal". The second says, "Read a number followed by…
canswered Guilherme Bernal 20,024 -
14
votes1
answer410
viewsA: Discrepant running times in parallel programming
About the time, the result is expressed in three times: real: This is simply the time you would count on a clock (often referred to as Wall clock). It is the difference between the start time and…
-
11
votes2
answers665
viewsQ: How to determine the smallest number of small areas to render?
I have two images (pixel arrays), one of which is rendered on the screen. The goal is to render the second. However performance is critical and, in the environment where I am, render each pixel is…
-
5
votes3
answers3071
viewsA: Does anyone know how to insert names in alphabetical order into a c++ vector?
If you plan for your list to be ordered, the simplest way to do this is to directly use a std::set, which is ordered and does not allow duplicates. The code looks like this:…
c++answered Guilherme Bernal 20,024 -
5
votes2
answers94
viewsA: Javascript error function. $. toJSON
The script probably makes use of the library jquery-json. Download it and include it in your project.
-
5
votes3
answers18362
viewsA: How to preview a loaded image in an "file" input?
Knowing this only works on browsers that support the Filereader API (which implies IE10+), you can do the following to read the file and as a Datauri by setting the src image. function readImage() {…
-
10
votes4
answers1519
viewsA: Why is 0.1 + 0.05 not equal to 0.15? What solutions can be used in R?
Why the vast majority of programming languages represent floating points using the standard IEEE754 or something similar. The point is that the numbers are represented as follows: (1.M) × 2E Whereas…
-
5
votes4
answers152
viewsA: Is a compiler allowed to omit a reference member in a class?
First, the standard states the following in section 8.3.2, paragraph 4: It is unspecified whether or not a Reference requires Storage. Then a compiler is free to omit the allocation of a reference…
-
11
votes4
answers152
viewsQ: Is a compiler allowed to omit a reference member in a class?
Consider the following class: struct Type { int a, b, c; int& ref; Type(int m) : a(m), b(m), c(m), ref(a) { } Type(const Type& ot) : a(ot.a), b(ot.b), c(ot.c), ref(a) { } } obj; Here we have…