Posts by Isac • 24,736 points
820 posts
-
1
votes1
answer108
viewsA: Change of binary basis to decimal basis
The logic that has works, but reading from the bit of lower weight to the one of higher weight. Which means you have to enter the bits in reverse than normal. To solve this particular problem and…
-
2
votes1
answer106
viewsA: Find an ancestor with a certain class from any descending element with pure Javascript
At this time pure JS also has a closest same as Jquery. It also takes a selector and is a Element, which in this case will be an element obtained from the FOD. See in the documentation. Your code…
javascriptanswered Isac 24,736 -
2
votes1
answer383
viewsA: Problem when removing all attributes of an object containing null values
Not enough a if with its delete in the right place ? In case the if you need to check the amount of keys that the object is left to after recursion, and if you get 0 removes the father. Example: var…
-
2
votes1
answer156
viewsA: Read char matrix from a binary file
The writing and reading in file you have is correct, the problem are some errors and your misconceptions in the code: As I said in comment printf is wrong to print a house that doesn’t exist:…
-
1
votes2
answers1195
viewsA: How to "break" a pure C string to assign the parts to other variables?
There are lots of ways to "break" a string in C, more robust, less robust, with or without dynamic allocation, but I’ll take exactly what I said: I tried to use the strtok(), but I was only able to…
-
4
votes3
answers1148
viewsA: Dynamic allocation in C - allocating without knowing the total amount of elements
as we have no way of knowing the amount of characters, we created the malloc, so the field will adjust to the exact size typed by the user, correct? Incorrect, both in static and dynamic allocation…
-
0
votes1
answer101
viewsA: Dynamic Chained List Creation
The question here refers to the classic typedef pointer that aims to help but often ends up visually deluding: typedef struct Elemento* lista; So it may not be very clear but lista is a pointer to a…
-
1
votes2
answers321
viewsA: How to place an integer at the end of a string?
The first problem that causes the code to fail is that it is not allocating space to the terminator in the string that passes to itoa. Remember that the result is a correctly completed string so it…
-
1
votes1
answer104
viewsA: Use of the getline() function in C with Mingw
It has two possibilities, and in both the idea is to use one of several implementations of the function getline that already exist there: https://dev.w3.org/libwww/Library/src/vms/getline.c…
-
2
votes1
answer51
viewsA: Unique elements of a matrix
The logic of the last for does not serve what you intend, this: for (i = 0; i < (l*c); i++) { for (j = i + 1; j < (l*c); j++) { if (vet[i] != vet[j] && i!=j) { printf("%d",vet[i]);…
-
3
votes1
answer102
viewsA: Is that a Python 3.6 bug?
This is a Python 3.6 bug? No, you would hardly find a bug in Python with such simple code. The issue here is lack of knowledge about python’s native functions. Watch out for what it says to…
-
1
votes1
answer346
viewsA: Error: expected Expression before 'dadosaluno'
The problem starts right at the first typedef: typedef struct{ int matricula; char nome [100]; float n1,n2,media; } dadosaluno[20]; // ^----- This did not do what you imagine. Here makes a typedef…
-
2
votes1
answer1662
viewsA: Vector union in the language C
The problem is something very small, this: if(achou == 0){ vetorAB[v+10] = vetorB[v]; // ^---- ate = ate + 1; } You can’t keep it based on v. Imagining that the array B starts with 3 repeated values…
-
1
votes1
answer51
viewsA: How to check if a code contains 3 letters and 4 numbers in this order?
In the way that its function verificaCodigo is written, it is easier to change the assignment you have in ifs to do what you want. So every time you see that a letter or a digit is not in the right…
-
1
votes1
answer677
viewsA: Could someone help me identify the error? 1179 Vector IV Completion -URI
The question here relates to a detail in the wording, this: However, the size of each of the two vectors is 5 positions. Then, each time one of the two vectors fills up, you must print out the whole…
-
1
votes1
answer72
viewsA: How to remove the dot (.) from a character array?
C does not have many ready-to-use functions for certain types of things, this being one of them, to remove a character in an array of characters. Taking into account that you also want to exchange…
-
2
votes2
answers302
viewsA: Hashmap to pick a value
Just to be a reference, we can also do how you came up with the idea of hashing the QU because his HashMap is of String. It’s even more organized if you have several combinations of two letters to…
-
3
votes1
answer39
viewsA: Nested loops and incrementation
To achieve this goal you only need to change the stop condition on for of the columns, to stop at the number after the current line. You can visualize like this: In the first line, line 0, goes up…
-
2
votes1
answer471
viewsA: Array of pointers with struct
The pointer notation used is not correct in some places according to the declared type. When it does: *(*p).vet[1]="Ana"; You already have a lot of problems, because vet is an array of strings, so…
-
5
votes1
answer1006
viewsA: Traverse array and take empty widgets
You can use the filter that returns a filtered array according to the criteria you want. In this case it is sufficient that the criterion is applied with the trim to cut the blanks and ensure at…
-
6
votes2
answers1771
viewsA: Logic for grouping data in javascript array
There are many ways to group, I will choose to show one with reduce. How your categories are linked to values in data according to the positions the code turns out to be a little more complicated…
-
1
votes2
answers472
viewsA: Error checking that fields are empty!
The mistake you see has nothing to do with saving the bank, but with the setters who is calling, who receive the value in Double, these: produto.setValorCusto…
-
6
votes2
answers144
viewsA: Print the result of a for JS inside a <p>
It turns out that each resultado is calculated within the for on the same variable and therefore when the for ends, in the resultado is only the last calculation. What you want is to concatenate the…
-
1
votes1
answer148
views -
1
votes2
answers142
viewsA: Error summing each row of a 5x3 matrix
The problem is in the parameters you have in the functions that are incorrect: int conta(int * matriz[5][3], int * vet) // ^-- aqui void imprimir(int * matriz[5][3], int * vet) // ^-- e aqui The way…
-
2
votes2
answers408
viewsA: Insert <li> and <a> via Javascript
For the html you are trying to generate, you need to dynamically create the tag <a>, also through the function createElement. Then the attributes of this <a> are placed using…
javascriptanswered Isac 24,736 -
2
votes1
answer284
viewsA: Stack operations
Most of the error is actually something very simple and even distracting, which is the fact that it’s calling the same function more than once: mpy(&p); // <-- mpy aqui…
-
0
votes2
answers41
viewsA: Doubt about inserting content from a file . txt to a list
Focusing directly on what was asked, it turns out that what is written in the list is the object that represents the access to the file, the f2: with open ('lista2.txt','w') as f2:…
python-3.xanswered Isac 24,736 -
3
votes2
answers181
viewsA: Problem about discrete mathematics - C++
As I mentioned in comment the problem is simpler than I imagined. Rangel only has one pair of socks of each color. So assuming he has for example 3 pairs of socks, and so N = 3, we have this: Now…
-
3
votes2
answers65
viewsA: Sum of n + last digit on the left
I personally think that these kinds of challenges that force a specific recursive solution are not very good, and end up generating code rather not intuitive and unusual, and that in the end has no…
-
2
votes1
answer88
viewsA: Error referencing Struct with Pointers
There are several things wrong, which probably arise from confusion about some concepts. Let’s start with the error: p.chave=1; //ERRO p is a pointer, so p.chave is invalid. First you have to access…
-
0
votes1
answer1515
viewsA: Invert row with column in a matrix?
To find the transpose of the matrix just invert the indices in the assignment of values, the row goes to the column and vice versa. Exemplifying in your code, creating the transposed matrix in…
-
3
votes2
answers1618
viewsA: How to go through string and replace ** with <b></b>
Regex is certainly the most practical and direct way to solve the problem as @Guilheremcostamilam has shown. The replace receiving a string like substitution works only for one substitution and not…
-
4
votes2
answers4471
viewsA: How to Store Strings in Vectors - C
To show another alternative, and in some ways as a complement to the @aa_sp response, you can also use an array of pointers to char. In this scenario it is necessary to allocate each name…
-
1
votes1
answer460
viewsA: Equal elements between vectors - C
You have several small errors in your code, which make it impossible for you to get the result you expected. Note that in the second for who thinks the repeated enrollment the amount of elements is…
-
4
votes1
answer73
viewsA: struct character array
The problem is in cin.get and how it works. Actually mixing different forms of readings: cin >> cin.get As a general rule, it creates complications, because there are scenarios where they do…
-
5
votes1
answer42
viewsA: Find array within a string?
Capture what is inside [ and ] is simple to do with a regex like: \[(.*)\] Explanation: \[ - Apanhar o caratere literal [ (.*) - Capturar tudo o que vem a seguir \] - Até encontrar o caratere…
-
1
votes2
answers153
viewsA: How to add two values of an input by checking checkbox
Each of the functions of change changes the final value of #tdmxp based solely on your checked and starting from the value 10, so you can never have the sum of the two, nor works for another value…
-
2
votes1
answer54
viewsA: recursive function error in c++
The problem is that at the end of the recursion you return 1 instead of returning 0 and that 1 is added to the value of the account. Just change to 0: int multiplic(int m1, int m2){ if(m2==0){…
-
6
votes2
answers278
viewsA: No match for 'Operator==' in find C function
The problem is exactly what the compiler tells you, who doesn’t know how to compare the two elements passed. Consider a structure representing a Cartesian point on a 2d plane: typedef struct { int…
-
0
votes1
answer203
viewsA: Filter and sort tags using Javascript
"Sort" html directly is more complicated than generating a new one based on data you have. And it even happens that in your case you end up doing appendChild to add an element that already exists in…
javascriptanswered Isac 24,736 -
2
votes1
answer156
viewsA: Why does this c code work?
Not to oversimplify, I start by saying this: You saw the result you expected, but that doesn’t mean it works. The code you have represents undefined behavior according to the C manual for any string…
-
2
votes2
answers58
viewsA: Exchange array data between’S' and 'N'
You have small errors of writing and logic that make your code not work: const isOn = (data.faltou = 'N'); - Notice that you missed the comparison in the right part of the expression, and what you…
-
1
votes2
answers557
viewsA: Know if value is in the unparalleled equality array!
Complementing what @Maniero has already said, you can use std::find which is part of the library algorithms to search for the element. O find receives 3 values, the initial, final element, and the…
-
2
votes1
answer548
viewsA: Stack Exercise - String with Trash
Your code has 2 problems being one more serious than the other. Use strlen in a string without terminator: saida[strlen(saida) -1] = '\0'; This is the most serious problem in the code that makes you…
-
0
votes1
answer2531
viewsA: invalid operands to Binary % (have ' float' and ' int')
You cannot use the modulo operator (rest of the entire division), the %, between a float and a int which is what happens here: float notas...; res100 = notas % 100; // float --^ ^---int Or changes…
-
1
votes3
answers1572
viewsA: How to read only whole numbers in the scanf?
By putting what you already got in the other code answers, you can test the return of scanf until 1 which signals that it has been able to read 1 entire successfully: int x; while (scanf("%d",…
-
2
votes1
answer394
viewsA: dynamic matrix allocation within a struct
my doubt is: I’m allocating the matrix correctly? Not really. The allocation was made based on the size of DIRETOR, allocating a vector of DIRETORES but the kind of filme is char**: diretor[i].filme…
-
2
votes1
answer47
viewsA: Cross-Reference with pointer array
When you debug a program, you usually find the error with some ease. In the case it happens that the phrase that is dealt with fgets let him the \n in the string, as expected. For this reason when…
-
0
votes1
answer48
viewsA: Help to understand hash usage error
The problem is related to the shape of the strtok works and with the fact that you are saving the original pointer returned by strtok. Note the reservation that the documentation does in relation to…