Posts by Guilherme Bernal • 20,024 points
220 posts
-
1
votes2
answers424
viewsA: QT signal from C++ to QML
I believe it is merely a syntax error with your QML file: ImageFilter { onTeste: image2.text = path } The value after onTeste must be a valid javascript code, not a definition of another property.…
-
6
votes1
answer95
viewsA: Excel Formulas doubts
If I understand correctly you have a list of values 1 2 3 4 5 6 And a key value X. You want to return the lowest value that is greater than X. Correct? If X is 4, you want the 5. Use the following:…
excelanswered Guilherme Bernal 20,024 -
2
votes2
answers114
viewsA: cho-han bakuchi in basic C
srand(time(NULL)); The problem here is that the value of time is the same all the second. So if you open the program twice in the same second you will have exactly the same output. A simple…
-
5
votes1
answer277
viewsA: cho-han bakuchi
Always Compile using warnings! If you use GCC or Clang, pass this option: -Wall to enable all main ones. You can add -Wextra to have even more alerts. They would point out some of the errors that I…
canswered Guilherme Bernal 20,024 -
4
votes1
answer96
viewsA: Auto benchmarking with moon
It’s not as clear as you’re generating the algorithms on the moon, but there are two simple ways to make the code run. The first is to lynch your program with the moon interpreter as a library. Then…
-
3
votes1
answer156
viewsA: Segmentation Fault and Error in typedef struct
The syntax for structs is as follows: struct nome { int membro1; int membro2; int membro3; }; struct nome objeto; Or: typedef struct { int membro1; int membro2; int membro3; } nome; nome objeto;…
canswered Guilherme Bernal 20,024 -
2
votes2
answers65
viewsA: Fopen typecast for comparison with NULL
You missed a parenthesis. Clang’s message is a little clearer: k. c:6:86: Warning: incompatible integer to Pointer Conversion assigning to FILE * (aka struct _IO_FILE *) from int [-Wint-conversion]…
canswered Guilherme Bernal 20,024 -
2
votes2
answers371
viewsA: Eliminating extra characters using scanf
A fairly simple solution is to consume the end of the line after each read. Remove %*[;\r\n] of your scanf. Then after each reading, whether it is successful or not, run a fgets with a reasonable…
canswered Guilherme Bernal 20,024 -
1
votes1
answer54
viewsA: Jplayer does not work on IE8
Simply put, IE8 does not support the element <audio> HTML5. It was introduced from IE9. See here the support table: Can I use Audio? On the library page:…
-
4
votes2
answers2590
viewsA: Struct member access error passed by reference
It is a mere matter of operators' precedence. The operator . takes greater precedence over the * unary. So: *p.salario Is read as: *(p.salario) And how p it’s not a struct, it’s a pointer to a, you…
-
4
votes2
answers3403
viewsA: CPF data in a C Struct
There are several ways you can store a Cpf in the memory/database. String: use a char[12], or else a char[11] since you know the size. Remember to never use operations that expect a string with null…
-
2
votes1
answer297
viewsA: Stack Frame - Example
In the end it is the compiler who decides and just looking at the source code you cannot complete anything. If you want to write a tool that automatically deduces this, you need to parse a compiled…
-
6
votes1
answer579
viewsA: Pass arguments to Makefile
You can use a rule that is just a pattern to redirect to some other rule. So it will capture anything that comes from the command line. Note: %: arquivo_%.pdf @# empty line arquivo_%.pdf:…
makefileanswered Guilherme Bernal 20,024 -
2
votes1
answer1128
viewsA: Performance: Switch or if aligned?
if a == 0 ... elsif a == 1 ... elsif a == 2 ... else ... end It is identical in semantics to: switch a case 0 ... case 1 ... case 2 ... default ... end Thus, a good tool will generate the same code…
-
5
votes1
answer2570
viewsA: Work with Struct and print problem, change Struct and delete Struct
When you discover that your program does not work for some reason, try to do your best to isolate the problem. The first step is usually to find an automated way to reproduce the problem, that is,…
-
1
votes1
answer111
viewsA: How to use a constructor with two or more classes?
In C++ constructors are not implicitly inherited by the derived class precisely to avoid this kind of ambiguity. In C++11 you can explicitly inherit one of the constructors using using, that would…
-
2
votes2
answers171
viewsA: How to insert an asterisk every 3 characters?
The logic for what you want to do can be written like this: Allocate a buffer of 134% of the original size to accommodate the string with asterisks. Initialize a variable i zero. Itere over the…
canswered Guilherme Bernal 20,024 -
5
votes2
answers343
viewsA: Regex in Javascript: grouping
Simply put, the delimiter for regular expressions is the bar /. If you pass a string to the constructor, you should not pass the bars inside the string, but they will be interpreted as literal. So…
-
3
votes1
answer119
viewsA: What’s the difference between creating a method and a block in a Ruby class?
class MinhaClasse def metodo # meu método end end What is happening here is quite simple: You are creating an instance method in the class MinhaClasse. Nothing out of the ordinary. class MinhaClasse…
rubyanswered Guilherme Bernal 20,024 -
2
votes1
answer201
viewsA: Problems running only one unit test on Rails 4
Quoting the documentation, in free translation: Rails adds a method test which receives a test name and a block. It generates a normal test of the MiniTest::Unit, with the name of the method…
-
18
votes5
answers12967
viewsA: Why is the use of GOTO considered bad?
goto INICIO; FIM: In conclusion: If you can write without using Otos, prefer. But if you do that and notice that the code has gotten bigger and worse, don’t be afraid to go back. goto SAIR; MEIO:…
-
1
votes2
answers1356
viewsA: Identify repeating elements within a two-dimensional array
a = [[1,"José"],[2,"Pedro"],[3,"Maria"],[4,"Lauro"],[2,"Pedro"], [5,"Léo"],[1,"José"],[6,"Caio"]] Walking through the arrays methods we can assemble the following: each_index iterate over the…
rubyanswered Guilherme Bernal 20,024 -
8
votes1
answer1324
viewsQ: What do the security modules commonly used in bank websites do?
Most banks offer some kind of security module that acts on the client side for access to internet banking sites. They are usually made in Java and are usually quite boring to install. What exactly…
-
74
votes5
answers17889
viewsA: Why choose C instead of C++ or C++ instead of C?
I will answer the question by pointing out some facts and advantages over languages. Make the choice on your own: C can be compiled on any architecture. One of the first things that happens when a…
-
5
votes2
answers1760
viewsA: How to format monetary values with C++?
Now, you practically have the answer yourself. Just modify the class you inherit from numpunct<char>. Implement the do_decimal_point to return a comma and do the do_thousands_sep return a…
-
6
votes5
answers2123
viewsA: How to validate CIS in ruby?
An explanation of the IEC validation can be found here: http://www.igoia.info/index.php/dicas-diversas/115-digitos-verificadores/74-cei-cadastro-especifico-do-inss Format: EE.NNN.NNNNN/AD Where: EE…
-
4
votes1
answer88
viewsA: String parse separated by null values
A C string is a string of characters completed by a null terminator. So since you have: const char* data = "[caminho da pasta]\0[arquivo 1]\0[arquivo 2]\0[arquivo 3]\0\0"; You can calculate the size…
-
21
votes5
answers18846
viewsA: What is a scripting language?
Scripting language is any language that is used to write a script. The big question is What is a script?. And this is quite subjective, a case-by-case analysis. The whole distinction is in purpose…
characteristic-languageanswered Guilherme Bernal 20,024 -
8
votes4
answers409
viewsA: How to transform, for example, "0" to "ZERO" in C? What problem in this code?
You stated char num1[7]. It is an array with 7 characters. But in C there is no array assignment operation. So num1 = "ZERO" doesn’t work. Can transform num1 and a pointer to char only, so when do…
-
3
votes1
answer179
viewsA: Subtract elements from a two-dimensional array
You can use the method each_cons. Observe: a = [1, 8, 17, 20] a.each_cons(2) {|pair| p pair } #=> [1, 8] #=> [8, 17] #=> [17, 20] Based on this you can do the following: x = [[2, 5, 16,…
rubyanswered Guilherme Bernal 20,024 -
4
votes1
answer255
viewsA: Field separation in array
How about using a function that was created specifically to read CSV? $array = str_getcsv($string); More details: Documentation…
-
3
votes3
answers901
viewsA: Infinite loop with $_SESSION and redirect
You must have a set of pages that require the user to be logged in (for example: View Profile, Admin Panel, Edit Article, etc). For these make your if and redirect to a login.php page. But you…
-
18
votes2
answers1067
viewsA: Is there a problem using Unicode characters for code identifiers?
Most modern environments actually support working with Unicode. But then to use this in the code has a large space. The first point to consider before thinking about aesthetics and good practice is…
-
15
votes5
answers145
viewsA: Strange behavior in a possible way to comment
Responding more directly: A Javascript comment is written as follows: // Isso é um comentário. /* Ou isso também é */ You can find more details in any book or reference you want. About specifically…
javascriptanswered Guilherme Bernal 20,024 -
1
votes2
answers281
viewsA: Two-dimensional array in Ruby
The beautiful thing about Ruby is that almost all these types of processing can be written in one line, without using loops directly. It’s like working with a functional language. Note: a =…
-
3
votes3
answers237
viewsA: Different outputs on different compilers
Your code uses a main function with the signature int main(int), that is legal, as other responses have already cited. However the GCC accepts such signature generating only a Warning, not an error.…
-
9
votes3
answers21946
viewsA: How to exchange the value between two variables without using auxiliary variable?
If using only integral types (int, long, unsigned char, ...) can use a trick with the XOR, like this: x ^= y; y ^= x; x ^= y; There is no limitation regarding the magnitude of the value. Yes, it…
-
3
votes2
answers3217
viewsA: split an array into several parts
You can see an array of C as being a mere pointer to the first element. It doesn’t even store the information of how many elements there are. Thus, usually functions that take an array as argument…
canswered Guilherme Bernal 20,024 -
6
votes3
answers1538
viewsA: Display from 1 to 1000 in C++ without using a semicolon
If that’s the point, let’s go: 76 bytes #include <cstdio> int main(int a,char**){while(printf("%d ",a++)&&a<1001){}} But if it is already in C, we can make it a little smaller…
-
8
votes2
answers32773
viewsA: Spacing between html paragraphs
If you’re limited to not using CSS, what you could do is use a single paragraph and separate with a simple line break. Thus: <p>primeiro parágrafo<br>segundo parágrafo</p> Upshot:…
-
8
votes1
answer4251
viewsA: Error "No such file or directory" when using mkdir()
The point is that the mkdir creates only a directory, not a sequence of them. For example, if you want to create the path arquivos/anual/2014/pdf/, the briefcase arquivos/anual/2014/ must already…
phpanswered Guilherme Bernal 20,024 -
12
votes1
answer673
viewsA: Does compiling on your computer really improve performance?
The fact is that when you compile a code with your compiler, by default it assumes that you want to distribute the executable to others. So as much as it optimizes, the code needs to continue…
-
5
votes2
answers3219
viewsA: C++ - Size of an array pointer
Given an array: int array[] = {3, 1, 4, 1, 5}; And a function: int funcao(int* argumento) {} The moment you call the function occurs a array decay for pointer. funcao(array); And from that moment it…
-
2
votes1
answer48
viewsA: Unusual behavior of variables captured by a clusure in a for
Duplicate of How to use the current value of a variable in a more internal function? Solution: Use an immediately invoked function to give a scope to the variable. list = [] for (var key in obj) {…
javascriptanswered Guilherme Bernal 20,024 -
2
votes1
answer48
viewsQ: Unusual behavior of variables captured by a clusure in a for
Consider an object obj whichever: obj = {q: 1, w: 2, e: 3, r: 4, t: 5, y: 6}; Now I’m iterating under the object keys and creating an anonymous function that uses this key: list = [] for (var key in…
javascriptasked Guilherme Bernal 20,024 -
3
votes1
answer982
viewsA: Chrome Extension x Delphi
It is unclear whether you want to communicate with a program written in Delphi on the local machine or remotely under the internet. In any case the solution is to open an HTTP server by Delphi and…
-
2
votes3
answers910
viewsA: Error in fgets function
You have a problem here between the use of arrays and pointers. char *f_name; Here declared a pointer with no defined value. When does: fgets(f_name, 100, stdin); The fgets() expects to receive in…
-
11
votes3
answers1211
viewsA: Concepts of Mesomorphic Allocation and Liberation in C#
You got two problems here. The first is the images that can remain indefinitely in memory. You do not call the method Dispose() of them and lets their reference fall out of scope. From that point…
-
1
votes3
answers258
viewsA: Accessing an SFML pixel
The simplest way to do this is by using the function getPixel(x, y) of sf::Image. Just call her inside your loop: for(int i = 0; i < largura ; i++) { for(int j = 0; j < altura; j++) {…
-
37
votes6
answers7191
viewsA: How to put default (default) arguments in a Javascript function?
The other answers are correct in general use, but if you want to be super strict and correct, you need to take the variable arguments under consideration. See this: // Função identidade, com…