Posts by Isac • 24,736 points
820 posts
-
0
votes3
answers1432
viewsA: Convert Double to Integer
I have tried converting using the method class Format, class String Which also works, as does the @Renanosorio response. Using String.format just need to set the formatter as %.0f to show without…
-
1
votes2
answers562
viewsA: How to use ("%10.2f",&d) in C I want the number to come out integer
First you are printing the variable memory address when using the operator &: printf("%10.2f", &d); // ^--- Then the formatter f, is for floating comma values as well as documentation…
-
3
votes3
answers790
viewsA: Capture javascript array element
One of the most direct ways to get the result you want is by using find which allows you to pass a function with the search you want to do and returns the first element that is valid for that…
javascriptanswered Isac 24,736 -
2
votes3
answers316
viewsA: Exercise changing last element
Just to complement and see other solutions to the problem, also manages to solve through a regular expression not very elaborate. Imagining you have the old word a to be replaced by KKK the regex…
-
3
votes2
answers112
viewsA: Implement a program that has a name and only has the last name and first name
When printing multiple elements with print the function already separates all of them by space, however, you have more appropriate ways of controlling the formatting of what writes on the screen.…
-
5
votes2
answers97
viewsA: Why can’t I access the array of integers in the main() function?
The problem is kind of subtle due to working with vectors and pointers, but it’s something simple. Imagine this scenario: void altera(int x){ x = 10; } Calling it that: int var1 = 50; altera(var1);…
-
0
votes1
answer57
views -
1
votes1
answer69
viewsA: How to allocate space for each structure of an array as the user wishes?
To modify the size of the vector according to what the user wants to use realloc as it is already using, but it has to increase in size with each relocation, which it is not doing. The most natural,…
-
1
votes1
answer1293
viewsA: Read from txt file to char vector
The reading that is being done not only does not allocate space for the terminator, but also does not place it. For this reason when trying to show the value in the console it picks up other values…
-
2
votes1
answer32
viewsA: Double-linked and circular list, memory errors with Valgrind
You allocate a new list using malloc but it doesn’t have the free corresponding to release this allocated memory. This is visible in the information given by Valgrind total heap Usage: 1 allocs, 0…
-
0
votes1
answer123
viewsA: Infinite Loop in Exception Handling
It turns out that there is an exception of the type InputMismatchException causes the content not to be consumed. So you are trying to read an integer and the user puts a text as "teste" an…
-
0
votes1
answer406
viewsA: Removing specific element from a double-linked list
The problem lies in the logic of what is in for And it’s mostly about the fact that you’re removing based on cartas that represents the beginning and not the knot that goes walking in the for. You…
-
1
votes3
answers286
viewsA: To create alphabetical list in PHP according to variable number
If the number of alternatives you need is less than the letters of the alphabet, you can do it at the expense of the function range. This function returns an array of all elements ranging from an…
-
3
votes2
answers51
viewsA: How to show only the number of a Cpf
It is always important to understand the mistakes we have made in order to evolve. In this sense your case the code even came close to working. The biggest problem was the nome[i].CharAt that is not…
-
5
votes2
answers5954
viewsA: What is the difference between using toString() and JSON.stringify()?
toString returns the string representation of the object, in the case of the question, of an array JSON.stringify converts a javascript value, in the case of an array question, to a JSON If you just…
-
1
votes1
answer669
viewsA: How to break lines according to a value
You can solve this problem with a simple regular expression in the form of: /.{1,8}/g Explanation: / - Inicio da expressão regular . - Qualquer caratere {1,8} - Entre 1 a 8 vezes, sempre apanhando o…
-
3
votes2
answers2190
viewsA: How to pass a matrix as a reference to a function?
One simple way to do this is to change the order of the parameters so that the dimension comes before the matrix, and with this you can already use the dimension in the parameter that represents the…
-
0
votes1
answer90
viewsA: Problem with Segmentation fault with whole pointer
The error has to do with the size of the elements allocated in stack with int pos[n][k] and others, that crosses the limit and generates a Segmentation Fault. You can try to set the size of stack so…
-
2
votes1
answer165
viewsA: White space at the end of each array index?
To remove spaces at the beginning and end of a string you can use the function trim. If you want to remove only at the end have a variant of trim that can use and that is called rtrim (name comes…
-
1
votes1
answer68
viewsA: My struct type is not recognized within my class
The problem is that its structure Node has a template, which will be used to create a Node of any kind, so you must also use this pattern in the class Pilha for the compiler to know what type of…
-
2
votes1
answer3977
viewsA: Warning: assignment makes Pointer from integer without a cast
Let’s start by first realizing the problems you have, and that are all related to the concordance in the types. Its function cria_palavra return a char: char cria_palavra(int i, char *aux, Lista…
-
1
votes1
answer54
viewsA: Why is my array not sorted? (Bubble Sort)
In the if which you have in the ordering part you are using j++ to access the next element: if(vetor[j] > vetor[j++]){ // ^-- aux = vetor[j]; vetor[j] = vetor[j++]; // ^-- vetor[j++] = aux; //…
-
2
votes1
answer50
viewsA: Doubt on a Language Issue C
The problem begins in the test done on if, here: if(foundUnique) { It should actually be the opposite, with the Operator not: if(!foundUnique) { // ^-- Because his foundUnique actually indicates if…
-
0
votes1
answer493
viewsA: Reverse Dynamic Stack
There are several details that are not right although the logic itself is right. I always advise to look with close attention for the compiler warnings as they are almost always errors and things…
-
1
votes2
answers47
viewsA: I want to write a loop for...of which changes the first letter of the day, in the array, to uppercase
Another interesting way to achieve the same result is with toUpperCase and slice. The slice serves to get the rest of the string without catching the first letter: const days = ['sunday', 'monday',…
javascriptanswered Isac 24,736 -
1
votes1
answer1942
viewsA: Sort list on in C
Ordering with copy of values The simplest way to demonstrate this for the code you have is through an algorithm like the Bubble Sort with the copy of the values of each structure. The difference is…
-
1
votes1
answer1146
viewsA: Dynamic stack - C
typedef struct TNo *TPILHA; //não entendi o motivo da criação dessa //struct It doesn’t create a struct. Is just one typedef that says a pointer to the structure TNo is now called TPILHA. Actually…
-
1
votes1
answer88
viewsA: Why doesn’t it list with innerHTML?
Turns out several calls in a row to document.write to write html on the page are all accumulated. See the example: document.write("um"); document.write(" pequeno");…
-
2
votes1
answer198
viewsA: C - How to pass an array in which it contains pointers to struct as a function parameter?
You have two possible syntaxes to do this. The first one is identical to the one you used for the parameter cartas thus: void ordenar(struct dados *cartas, struct dados **ponteiros, int n){ // ^---…
-
3
votes2
answers221
viewsA: How to transform my code with static memory struct to C dynamics?
Dynamic allocation with vector Dynamic allocation is as simple as calling malloc directly: Dado *pimpolho = malloc(sizeof(Dado) * (num+1)); The rest you have works because when you do pimpolho[i] is…
-
6
votes5
answers691
viewsA: Method Reverse returns None
Whenever in doubt consult the documentation! Note the documentation for the reverse: list.() Reverse the Elements of the list in place. Translated means: it inverts the elements directly in the…
-
1
votes2
answers908
viewsA: Python - Transforming lists into a single list
Using recursiveness and comprehensilist on looks good short: def lista_simples(lista): if isinstance(lista, list): return [sub_elem for elem in lista for sub_elem in lista_simples(elem)] else:…
-
2
votes2
answers1821
viewsA: How to implement a queue using two stacks
Since @Fabiomorais has already responded with a possible alternative implementation to the problem, I take the opportunity to show an implementation from the code you have and changing as little as…
-
2
votes1
answer557
viewsA: Count how many columns are in a C++ CSV file
Problems The csv file has all the contents inside double quotes(") soon the comparison you have will never work: if(buffer == "SG_PARTIDO" Getting around this problem is by comparing with quotation…
-
1
votes1
answer1260
views -
5
votes3
answers337
viewsA: How to find the occurrence of equal integer values in a vector?
My answer serves as an alternative to @Severmateus without using streams and totalizing with a normal array as if it were a HashMap. In this case it is simple to do because the range of possible…
-
4
votes2
answers414
viewsA: What is the code to print only the first number of a value? ex: only the 8 of 8372883
First digit To get only the first digit of a number, you can calculate the number of digits using base logarithm 10 and with that quantity you get only the first digit through a division. Example…
-
3
votes2
answers1242
viewsA: Regex to extract email address from a string
If you only want to capture what’s inside < and > then you can use a simple regex like: <(.*)> Explanation: < - caratere menor (*.) - tudo o que está no meio como primeiro grupo de…
-
2
votes1
answer41
viewsA: Unzipping of characters
The problem is that at the beginning of decompression the value is lost in the first and binary that is made: void descompactaCaracteres(unsigned valor){ mostrarBits(valor); valor &= 65280; //…
-
7
votes1
answer115
viewsA: How to identify if an item has been removed from the page in real time
If you want to understand when the FOD is changed you should use Mutationobserver. This allows you to define a callback which it implements whenever there is a change in a given element and its…
javascriptanswered Isac 24,736 -
3
votes1
answer131
viewsA: C pointers
Attention to this type of typedefs: typedef struct digraph* Digraph; You should avoid this kind of typedefs with pointers because they end up masking the guys and giving you the wrong idea,…
-
6
votes3
answers108
viewsA: How to write a large amount of values per line in Python file?
The action you intend to perform is to join, which is given by the method join of string. This allows you to join any amount of elements of an iterable using a string as a separator between them.…
-
4
votes2
answers930
viewsA: Prototype functions in C/C++
However I remembered a common situation where this is used and that probably also helps to contextualize, which is in an ordering. Just as @Maniero already explained this are pointers to functions,…
-
3
votes1
answer885
viewsA: How to change the state of complex objects in React?
For widely nested structure I find it preferable: Replicate the state on a local object in order to preserve the original. Change what you want in this object Call the setState with that new state…
-
0
votes1
answer35
viewsA: Problem with a string attribute of an object
The question is what you’re using printf to show what a string in pure C, that is to say a char*, but you actually have a std::string and not a char*. This problem is visible when compiling. See the…
-
4
votes3
answers718
viewsA: Assign values to arrays
Just to add a little more information to what @Maniero has already said, if you use numeric indices continue to use the array as a normal array. See with the index 10 for example: let array = [];…
-
3
votes2
answers51
viewsA: How to style css with javascript searching for classes
Let me start by mentioning that getElementsByClassName returns a list of widgets that have the specified class. You must pass only the class name that would be answer and not .answerr as it did, for…
-
5
votes1
answer52
viewsA: Why is the size of the vector being changed in the function?
This is because when you pass the vector to the function you only get the pointer to the first element, just when you do the sizeof takes pointer size and not vector size. Something simple that…
-
3
votes1
answer230
viewsA: Declare MAP already passing values in C++ ?
Actually your example of booting the map got to a {} to be right! It would only be enough: map<string,int> mymap = {{"a",1}}; // ^ ^ The question is what the first pair of {} represents the…
-
1
votes3
answers1365
viewsA: Creating html elements in javascript looping
The other answers you have already explain the problem and what you did wrong, but I want to show another solution to the same problem. If you need to add a lot of html dynamically you can use…