Posts by vmp • 469 points
39 posts
-
0
votes2
answers88
viewsA: Arithmetic Burst C++
The guy double is more accurate than the type float. You can change the varietal type r and a for double or change the literal to 3.14f to be interpreted as float. If you don’t put the suffix f the…
-
1
votes1
answer36
viewsA: How to return a pointer to a dynamically allocated String, declared within a function?
You’re allocating too much space. sizeof(source) is different from the size of sizeof(*source). You’re starting to write on top of \0 => count = size - 1; Is writing the \0 outside the allocated…
-
0
votes3
answers50
viewsA: Does anyone have any idea why the if not be executed?
You just want to compare the first char? strcmp compares the entire string. It would only pass in if its string was only "[". Compare only the first position: if (letra4[0] == '[')... This imagining…
-
0
votes6
answers342
viewsA: Get a list of the first multiples of a number
Your code is working. But there is a more practical way to do it: lista = [] for n in range(3, 100, 3): lista.append(n) print(lista) This way you already jump 3 by 3, without having to make checks…
-
0
votes2
answers73
viewsA: Dynamic lease in C++
You can’t guess, can you? But what you can do is allocate from a size that you think will be enough and after it type the string you realoca it to the size actually used. int main() { char *st =…
-
0
votes1
answer32
viewsA: store two pieces of a string in two other strings
Your reading is wrong. %s will stop at the first blank. You are copying memory in uninitialized variables that are supposed to be strings, will give problem. If you know that the first string will…
-
0
votes1
answer56
viewsA: Python function prints the result but Return = None
I don’t know what that is np.matrix(puzzle) but if you put one up for print you’ll see that the function is doing what it should: def resolver(puzzle): for lin in range(9): for col in range(9): if…
-
2
votes3
answers56
viewsA: Python Problem with exercise
There are 2 basic problems in your logic: Its function getFactors(x) traverses the interval [1, x]. Which works well for your cousin implementation, although it goes through more elements than is…
-
0
votes1
answer41
viewsA: I need to change the output of a variable in Python
Add the following line: a = [i[0] for i in a] You have a list of lists. This compression will take the first element of each list and put in a new list. If there can be more than one item in each…
-
2
votes2
answers44
viewsA: Error in a simple program
The order of aguagasta * price = total; ta wrong. What you want is: total = aguagasta * price; Take the quotes from 20in the if: if (aguagasta < 20 && aguagasta > 0).…
-
0
votes2
answers56
viewsA: How do you determine how many people would have to receive extra pennies in a room
Makes whole. Multiply the value of the account by 100. In your example, that the account is 100.00, would be 10000. Remember to use the value as integer after multiplying by 100. Takes the value of…
javascriptanswered vmp 469 -
-1
votes2
answers120
viewsA: How would I get the user to register a name and password to log in?
I changed a few things and adapted to something functional. dados_login_e_senhais a dictionary that serves to associate a value to another: A password to a login in this case. def…
-
0
votes3
answers87
viewsA: Working logic error with list
What you’re doing in the loop is adding a reference to the C dictionary at the end of the list. Every time you change C, it will change, these changes will be reflected in the list. To do what you…
-
2
votes1
answer30
viewsA: Problems with C/C++ Struct Array
Getting a '\n' in the buffer after you read the whole... As the next reading is of a whole line, it ends up getting in the way. You can do the following to fix: for(i = 0; i < 3; i++){ cin…
-
-1
votes2
answers50
viewsA: How to avoid Greedy Repetition (.*) to search for string that has defined start, dynamic middle and defined end?
adds a ? after the * so that he stops being Greedy.
-
0
votes1
answer31
viewsA: How to check if a data is already on my list
You are doing assignment where you should be comparing (you are using = where you should use ==) in the following lines: if((aux->num = dado)) and if((resp=1)) In the latter if you do not need to…
-
0
votes2
answers364
viewsA: How to calculate the number of times a word appears within a sentence
your mistake is in this line: if (palavra[j] = frase[i]) is assigning, not comparing, the operator you want is == if (palavra[j] == frase[i]) And at the time of reading for strings you don’t need…
-
0
votes2
answers129
viewsA: Matrix with C++ Strings
The vector class can make your life easier: vector<vector<string>> matriz({ { "3325309756482910474", "CARRO", "2506794813021649539", "618.57"} , {"3325309756485249504", "MOTO",…
-
0
votes1
answer29
viewsA: Problems in displaying the result of a C function
Look at the condition in the for... you start with i = n; And compares: n < m; But the variable you’re increasing is i... Or do you compare i with m... or increases the n.…
-
0
votes2
answers152
viewsA: Ordering values by pointers
The error is in both. The error of the pointers is in Ifs, failed to use the asterisk: if (*x < *y) if (*y < *z) if(*x < *y) && (*y < *z) The logic error is in the expression…
-
4
votes2
answers187
viewsA: How to check if the typed string is only '0' and '1'?
Ever heard of regular expressions? The following regular expression can help you. import re teste = "101010" print(re.match("^[10]+$", teste ) != None) The value you want to test is in the test…
-
0
votes3
answers396
viewsA: Doubt: dynamic list chained inside another, in C
Look, you declared three pointers, one for each type of list. I didn’t understand the logic in that. What you want is probably just a pointer to Band (I’m guessing whenever you register a Album you…
-
0
votes1
answer36
viewsA: Delete queue element and release memory for this function?
Yes, it’s releasing! You can check the addresses with printf("%p"); Puts a: printf("%p\n", aux); before returning it, and a: printf("%p\n", cel); before giving free, for you to see that it is the…
-
0
votes2
answers51
viewsA: C++ - pointer this
Yes, if you want to return the object itself you change the prototype to return a reference. Exchanging: mat4 mat4::Scale(float x, float y, float z) for: mat4& mat4::Scale(float x, float y,…
-
0
votes2
answers38
viewsA: How to make a concatenation between a string and another primitive type in a function return?
Uses to_string: string statusConta() { return "\nDono: " + to_string(getDono()) + "\nAberta: " + to_string(getStatus()) + "\nNumero: " + to_string(getNumConta()) + "\nTipo: " + to_string(getTipo())…
-
0
votes2
answers42
viewsA: Why not print the contact variable[0]->a?
You’re declaring a pointer to 2-position vectors and not allocating... Since it is a global variable, it is being initialized for NULL, test the following: if(contato[0] == NULL) printf("valor nao…
-
0
votes1
answer51
viewsA: Return string format from another struct
That pointer there is not with memory allocated to it... My suggestion is to create a temporary variable of a slightly larger size and then allocate space based on the final size of this string,…
-
0
votes4
answers744
viewsA: How to get the highest and lowest number among 15 typed numbers? C++
Read a number, consider this number to be both the largest and the smallest so far. Read the other 14 and compare with the largest and smallest so far. #include <iostream> using namespace std;…
-
0
votes1
answer54
viewsA: What am I missing when using EOF in this case? C language
Running in the terminal? If so, you can save what your input would be in a text file and test by redirecting the input. Assuming the data file is named input.txt, you can run as follows.…
-
0
votes2
answers556
viewsA: Receive multiple strings in the same row in C
There is no need to use dynamic allocation for your program, since the value is constant and even if you decide to continue using dynamic allocation, defining constants is a recommended practice to…
-
0
votes2
answers59
views -
0
votes2
answers512
viewsA: Chained List in C Language print inverse list
If you use recursiveness your code can be much simpler. I suggest the following amendments: 1 - in the header: void imprimir_lista_inverso (struct no*); 2 - on call: imprimir_lista_inverso (node); 3…
-
1
votes1
answer28
viewsA: Program ignores the first scan of the loop
Strip the n of the scanfs. You only need to put it if the later reading is of characters or strings. scanf("%d", &lista1_coordenadas[i].x);
-
0
votes2
answers1112
viewsA: regex for url validation
Take a look at this change here: const std::regex pattern( "(?:(ftp|http[s]?:[//])?)?([w]{3}[.])?" "(.*[.](com|php|net|org|br|dk|at|us|tv|info|uk|co.uk|biz|se)?)?"…
-
1
votes1
answer93
viewsA: This method must Return a result of type int[][]
All paths in your code need to have a return. You have specified the return within the IF, but if you do not enter the IF function follows to the end without any return command. There are 2 simple…
-
1
votes1
answer61
viewsA: Problems when deleting the first element from the chained list
Boy, your code is pretty messed up but just by the description of the problem I can see what the problem is. There are 2 possible solutions: Pass a pointer to the pointer as a parameter to treat the…
-
0
votes2
answers69
viewsA: How to see if a string has integer numbers
There is already an isdigit function in the ctype library, no need to implement a. Add a while to print all consecutive digits: for (int i=0; i < str.length(); ++i) if (isdigit(str[i])==true){…
-
1
votes1
answer83
views -
0
votes4
answers1489
viewsA: Cleaning the Buffer after getchar
Only insert the n at the end of the reading of the number it will not be in the input buffer: scanf("%f\n",&salario); scanf ("%c",&sexo);