Posts by Emoon • 966 points
31 posts
-
0
votes2
answers163
views -
2
votes1
answer284
viewsA: How to get the time in seconds of a date in string format?
There is a this struct used to manipulate dates. I think what you want is something like that: #include <stdio.h> #include <time.h> int main() { struct tm tm = {}; // inicializa com…
-
4
votes1
answer74
viewsA: Could you help me with Mergesort?
gcc itself points out the error: test. c: In Function ːmain': test. c:41:15: Warning: Passing argument 2 of ːMerge' makes Pointer from integer without a cast [-Wint-Conversion] Merge(vet,aux,0,9);…
-
4
votes2
answers886
viewsA: compare and remove repeated element
You can do an extra check when adding an item. If it already exists, simply don’t add: public void adiciona(Autor a) { for (Autor b : autor) { if (a.equals(b)) return; } this.autor[cont++] = a; }…
-
3
votes1
answer156
viewsA: How to uninstall a tar.bz2 package?
As stated in the instructions, the files were copied to the directories /usr/local/bin and /usr/local/lib. Just for the record, distributions like Debian have a differentiation by default: manually…
-
2
votes2
answers56
viewsA: Declare local classes as public
You can set a "generic" pointer for the mother class Enemy just before the switch: Enemy *enm, and within the switch make the appropriate instantiations: enm = new Monster(); ... enm = new Enemy();…
-
1
votes1
answer158
viewsA: How to create a "back" link
Try a link this way <a href="#" onclick="history.go(-1); return false;">Link</a>
-
3
votes2
answers100
viewsA: Assigning Strings to a Date List
If you order print arrayList, obviously it will print it whole. The solution is to use an iterator, increment it modularly and print only the position of that index: int i = 0; for (Calendar cal =…
-
1
votes3
answers289
viewsA: Error Segmentation fault without indentification
There are some problems in your program. strcmp, in the case of equality, returns 0, not the other way around. In addition, the fgets has the drawback of not eliminating the \n at the end of the…
-
1
votes1
answer52
viewsA: Python procedure for Problem class
In Python, the object itself is always passed as an implicit argument to its respective methods. Therefore, the interpreter complained that you passed two arguments (itself and the string), but in…
-
0
votes1
answer2690
viewsA: Program Received Signal sigsegv Segmentation fault
First, variables are not used in size statements arrays, even more so before you even define them, as you did in matriz[n][m]. Put whole numbers as sizes or set your own constants with #define and…
-
4
votes1
answer1726
viewsA: Difference between fflush and setbuf
fflush(stdin) is used erroneously to clear the default input buffer, but causes undefined behavior according to the standard of the language, therefore it should be avoided at any cost. Particularly…
-
5
votes1
answer4379
viewsA: Difference between sorting methods Selection Dort, Insertion Sort and Bubble Sort
Selection Sort: At each iteration, it searches the entire unordered portion of the vector for the smallest (or largest) element and places it in the correct position. Thus, in the ith iteration, the…
classificationanswered Emoon 966 -
0
votes1
answer114
viewsA: Push Back with copy builder
This happens because of the need to resize the size of std::vector due to push_back(), which results in extra copies. Reserving space a priori, this "problem" does not occur. vector < foo > v3…
-
7
votes2
answers146
viewsA: Pointer changes address when exiting function
This is a classic problem in C. What happens is that the pointer vetorInt is local to the scope of the function aloca (in the same way as the whole tamanho is also). You modify its value within the…
-
1
votes1
answer33
viewsA: Know when a file row starts with a given string
You can read the initial string and, depending on the content, take a different action. char aux[16]; fscanf(arq, " %s", aux); if (strcmp(aux, "o") == 0) { ... } else if (strcmp(aux, "usemtl") == 0)…
-
1
votes1
answer877
viewsA: Read text file picking float numbers and playing in matrix
The fscanf has a smart formatting system. If the lines you need to read follow this pattern (starting with v and followed by 3 floats), then you can do something like: fscanf(arq, " v %f %f %f",…
-
1
votes1
answer239
viewsA: Function that reverses the values of the vector into another vector
There is no need to return anything. Vectors in Java are passed by reference, so changes occurred in GeraInverso are reflected in the main.
-
0
votes1
answer157
viewsA: How to remove vector character by pressing Backspace on c
First of all, getch() and fflush(stdin) are two of the most harmful things in C; the first is not part of the pattern and the second generates undefined behavior. If the intention is to just read a…
-
4
votes1
answer275
viewsA: What is the purpose of while(*variable) and if(!*variable) in the statements "while" and "if"?
In the code in question, List is defined as typedef node* List; Soon, head is actually pointer pointer to a knot, and *head, therefore saves a pointer to node. The part of the while could be written…
-
0
votes3
answers208
viewsA: Repetition of elements
To find the number of repeats, there are some options: Use a Boolean vector also of size N to store visited houses. For each home of the original vector, search the remaining houses for repeats. If…
-
2
votes1
answer1940
viewsA: Typeerror: can’t Multiply Sequence by non-int of type 'str'
The function input() does not return a list, but a string. It is necessary to break the string into spaces, generating a list of strings, and then transforming them into integers, so that arithmetic…
-
2
votes1
answer66
viewsA: Specialize only one template class method
A possible solution is to make different versions of the method depending on the template class. template<> int ClasseC<ClasseA>::retValorFinal() { std::cout << "Classe A\n";…
-
1
votes2
answers767
viewsA: Error in "utf-8" in python 3
Error happens in the following line: text = page.read().decode('utf8') It attempts to decode the page of the aforementioned site using UTF-8 encoding, but fails to find any poorly formed byte. The…
-
2
votes1
answer436
viewsA: Implementation of C strcpy function in MIPS using MARS simulator
Apparently you were loading origin and destination as words, and not their respective addresses. For this it is necessary to use la instead of lw. Doing this and a few more changes, it works: .text…
-
1
votes3
answers95
viewsA: How to search a string for X and replace it with a number and use it to calculate?
If the intention is to replace x in the string by a value, this is easily solved with a loop: for (int i = 0; i < strlen(s); i++) { if (s[i] == 'x') s[i] = numero; } The only problem is that the…
-
2
votes1
answer2495
viewsA: Bubble Sort in Assembly (MIPS)
Your idea of Bubblesort is wrong. This sorting algorithm has some variants, but basically works as follows: Start with i = 0. j begins in n-1 and decreasing. At each iteration, it moves through the…
-
0
votes2
answers724
viewsA: Delete a space allocated by malloc
When you make a malloc call, in simplified terms the OS stores a record of the memory position that you have been given for use and how many bytes from it are available. So do something like…
-
1
votes2
answers668
viewsA: Function help to delete repeated values contained in a double-chained C List
Your remove functionValue() is only taking the first value from the list and checking if it is duplicated. If the intention is to remove all duplicates, it is necessary to iterate between all the…
-
1
votes1
answer355
viewsA: I cannot close a tab(tab) with javascript
I don’t know if it is possible to close it directly, but one option is to find iframe by its ID/class on the page that contains it and then remove it.…
-
1
votes2
answers174
viewsA: Doubt in recursive function
As already commented, probably the original intention would be to call as parameter --n. Anyway, that’s dangerous and spoils the operation, because order of precedence of operators in C, the…