Posts by zentrunix • 5,511 points
272 posts
-
3
votes2
answers177
viewsA: Doubt in exercise with factorial and large numbers
Problem 1: You have to do the floating point math, otherwise the x/y split result when x < y will be 0. Problem 2: The "result" variable needs to be initialized. I did a test (well) fast, it…
-
1
votes1
answer66
viewsA: Function does not return the value I want
It is necessary to change the declaration and the use of the function "calculation". Option 1: int calculo(int, int); int main() { .... p1 = calculo(bet1a, bet1b); printf("%d", p1); ... } int…
-
1
votes2
answers700
viewsA: Failed to execute "cmake." command at the prompt
You need to have some Visual Studio installed, it can even be Express or Community. (Warning: Redistributable is not compiler). Also you have to use the right "Enerator", each version of Visual C++…
-
2
votes3
answers559
viewsA: What’s the best way to play a Loop in math?
That sounds like a recurrence relationship to me. The mathematical representation could be E₀ = 0 Eₙ₊₁ = (Eₙ + n) * (n + 2) (para n > 0) In the Wikipedia. Obs. I am putting Wikipedia as a…
-
2
votes1
answer377
viewsA: FOR syntax in C
The for(;;) command is an infinite loop. To exit this loop you normally use the break command. Thus for (;;) { ... ... if (alguma_condicao) break; // sai do loop ... ... }…
-
0
votes2
answers264
viewsA: Problem decreasing the size of a stack in c
Problem 1: typedef struct viagem { char nome[50]; // char uf[2]; // <-------------- ERRO char uf[3]; } v; Problem 2: void desempilhar (p *pilha){ if (pilha->topo >= 0) // <------- FALTA…
-
0
votes2
answers168
viewsA: calculation of media in programming c
The calculation of the mean is not a question of programming, but rather a question of mathematics. How do you calculate the mean of n numbers ? You sum the n numbers, and the result of the sum you…
-
0
votes1
answer925
viewsA: Series of Taylor for cos(x) - in C
The OP has already solved its doubt, but for the record, here is an optimized version, which calculates the factorial without recursion and without repeating operations. You can still improve a…
-
0
votes3
answers447
viewsA: Problem in the use of malloc and realloc
The code posted has several problems, which I explain below. #include <stdio.h> #include <stdlib.h> static void f(int **matriz); int main() { int **matriz; // nao faz sentido passar um…
-
0
votes1
answer59
viewsA: I’m having trouble printing a variable in my program
Just looking at the code you posted is not possible to know why it does not work the way you want it, probably have logic error in the part that was not shown. But it is possible to make some…
-
2
votes2
answers1731
viewsA: Insert elements into array of C++ lists
Firstly, it is not advisable to mix operations of e/s C++ (Cin/Cout) and C (printf/scanf), you need to treat errors of two things (C++ and C) instead of one (C++ or C). Second, when…
-
1
votes2
answers203
viewsA: Sum of series 1+(2*3)+(4*5*6)+...+ n with iterative implementation?
I found that this problem is not as simple as it seems, at least to solve in an elegant way. Moreover it is not well defined: what happens when parcels are missing in the last term of the sum ?…
-
2
votes2
answers60
viewsA: Matrix initialization not working from a given line
Since C is a relatively low-level language, the simplest way to solve this problem is through bit manipulation. This problem, although easy, is not trivial. So to create a solution it is necessary…
-
0
votes2
answers477
viewsA: I need help to calculate the factorial in ascending and descending order in an equation!
An optimized solution, taking advantage of the details of the problem definition: the value of x alternates from - to +, the exponent starts with 2 and grows, the factorial table is fixed. #include…
-
0
votes2
answers199
viewsA: Error in c++ stringstream write function
That code is unnecessarily complicated. Below a very simple solution. #include <iostream> #include <string> using namespace std; static string toBin(int valor) { // quantidade de bits…
-
1
votes1
answer1682
viewsA: Check if a letter exists in the c++ string
This code has nothing of C++, taking the declaration of the function. You have made several basic mistakes. I corrected below but have not tested the operation. int…
-
2
votes2
answers716
viewsA: Count number of cells in a chained list
Segmentation failure occurs because you did not initialize the "current.Prox" field when you declared the "current" variable". int main() { int n1; celula atual; int tecla = 10; celula *pointer;…
-
0
votes4
answers65
viewsA: Beginner program error in C
This answer is a reformatted version because the program as it was posted is badly formatted. int main () { double salario, aux; printf("digite seu salario: "); scanf("%lf", &salario); if…
-
0
votes1
answer229
viewsA: How to capture packets from a TCP connection using a proxy?
You are only binding on the localhost interface, you have to bind on all interfaces. To do this you use the ip address 0.0.0.0. class Proxy { Proxy(String host, int port) { //…
-
1
votes2
answers1273
viewsA: What is the difference between "in pairs" and "in ipairs" in Lua?
The "pairs" iterator traverses the entire table. The iterator iterator "ipairs" traverses the table using the indexes/keys 1, 2, etc. Your table has no keys 1, 2, etc., its keys are "rice" and…
-
1
votes2
answers71
viewsA: What is the meaning of the two points on that line?
These two dots indicate a list of initialization, that is, a list of call constructors of data members of the class. For primitive data members (e.g., "int myField" in your code) in practice the…
-
1
votes1
answer40
viewsA: How to load all . lib in a directory through Cmake?
I think the way you put it in the question is the way "right". But I also think you can do it the way you want: ... link_directories("${CMAKE_CURRENT_SOURCE_DIR}/../lib/ffmpeg/lib")…
-
0
votes3
answers1015
viewsA: The sum of all non-prime odd numbers that precede an integer?
You must implement the algorithm Sieve of Eratosthenes in your code, and save in an array the numbers that do not pass through the sieve. After that you traverse the array with the numbers that did…
-
0
votes1
answer382
viewsA: error: expected Primary-Expression before = - Error during object creation:
The "main" statement is wrong, it must be int main() // note o "()" { .... }
-
0
votes1
answer75
viewsA: Expected operando in for loop shell script
I’ve removed the syntax errors, but I think your logic is flawed... #!/bin/bash ehPrimo() { n=$1 # primeiro parametro e' $1, nao $0 numDivisores=1 for (( i = 2; i < n/2; i++ )) do ((x = n % 2)) #…
-
1
votes1
answer34
viewsA: Looping in a validation within a matrix
Failed to redo data input when number is not odd. for (l = 0; l < 5; l++) { for (c = 0; c < 3; c++) { printf("\n * \n"); printf(" Linha [%d] | Coluna [%d] \n", l+1, c+1); scanf("%d",…
-
0
votes1
answer141
viewsA: Error when compiling a solution in c++ in visual studio 2017
In C++ it is illegal to overload two functions that differ only by type of return. _Check_return_ _ACRTIMP int __cdecl ilogb(_In_ double _X); _Check_return_ _ACRTIMP double __cdecl _logb(_In_ double…
-
0
votes1
answer174
viewsA: How to run cmake using MSYS2 without having to configure environment variable on Windows
Create a cmd to run cmake: call_cmake.cmd @echo off :: nao exporta as variaveis de ambiente para o cmd externo setlocal set PATH=path_gcc_mingw;%PATH% :: chama cmake... :: etc To compile, same…
-
1
votes2
answers67
viewsA: Cmake accuses multiple statements of a class
There are a lot of things wrong with this project. Here’s a solution that works. Can be (well) improved, but at least compiles and runs without errors. Cmakelists.txt cmake_minimum_required(VERSION…
-
0
votes2
answers292
views -
1
votes1
answer703
viewsA: I can’t dynamically allocate a struct vector in C
Original program corrected. #include <stdio.h> #include <stdlib.h> struct dados { int numero; char nome[5]; }; typedef struct dados Das; void manipula_um_par (struct dados *a, int b) {…
-
1
votes2
answers2032
views -
1
votes2
answers263
viewsA: How can I pass a parameter of any type to a generic vector? - C
Use pointer to void. TTabelaX*cria_tabela(int tam) { // Aloquei a estrutura e passei o endereço pra aux TTabelaX* aux = (TTabelaX*)malloc(sizeof(TTabelaX)); // Tabela aponta p/ um vetor do tipo…
-
0
votes2
answers597
viewsA: How to enter data at runtime?
You can redirect the input of a file. Password file.cmd @echo off echo Lendo senha... set /p senha=< senha.txt echo Senha digitada: [%senha%] Password file.txt 123 Whirling: c:...> senha.cmd…
-
1
votes1
answer169
viewsA: free() in char dynamic stack does not work - C
From the information that is in the question it is possible to see that there is (at least) one thing wrong: in the creation of the pointer vector it is necessary to initialize the pointers, which…
-
0
votes3
answers1075
viewsA: I want to pass a parameter that is in the main for a function and perform a calculation, pointer exercise and function, how do I do?
Apparently the question is "how to pass a pointer parameter to a function". Solution: use the operator "&" to pass the pointer in the function call, and use the operator "*" to pick up the value…
-
0
votes1
answer14
viewsA: remove include scores to point local folder
In the compilation line you must pass the option "-I..". If it is Visual Studio, use "/I..". (Actually the Visual Studio compiler also accepts options initiated by "-" but usually "/" is used…
-
2
votes2
answers186
viewsA: Unexpected output when printing substring
I think with awk can do what you want: $ find . . ./bbb ./bbb/bbb.txt ./aaa ./aaa/aaa.txt ./ccc ./ccc/ccc.txt (pegando so' os arquivos) $ find . -type f | awk -F/ ' { print $2 }' bbb aaa ccc $…
-
1
votes1
answer41
viewsA: Problems with the malloc function
In the general case you cannot replace "new" with "malloc" because when you use "new" the class constructor (fuzzy in this case) is also executed... If you call "malloc" instead of "new" then you…
-
4
votes4
answers3410
viewsA: What is dynamic programming?
A known and simple problem that is commonly used to demonstrate dynamic programming is the recursive calculation of Fibonacci numbers. In Moon this calculation is made so: function fib(n) if n == 0…
-
0
votes2
answers144
viewsA: Operation of function scanf()
I’m not going to explain much, I’m going to show you something that people have a lot of difficulty with C: keyboard reading. The program below reads 2 whole numbers per line. The program will only…
-
0
votes1
answer78
viewsA: When the input is greater than 9 the program reads only the first digit
Use integers and make data entry consistency, as in the example below. #include <iostream> #include <string> using namespace std; int main() { int opt; for (;;) { cout << "* digite…
-
0
votes3
answers2698
views -
1
votes4
answers249
views -
0
votes1
answer55
viewsA: Variable changes value without apparent reason in C
This line is wrong // for (int j = 0; j < 397; j++) produto[j] = 1; // Inicia variéveis do 0 ao 396 // *** erro It must be so: for (int j = 0; j < 396; j++) produto[j] = 1; // Inicia variéveis…
-
1
votes1
answer216
viewsA: How to pass a vector as a parameter of a function in C++?
The usual way to pass "large" variables in C++ is by reference: // declaracao do vetor de strings vector<string> matriz_ambiente; ... ... // declaracao da funcao void…
-
1
votes1
answer559
viewsA: Visual Studio Character Error
Probably the "regional settings" of your Windows are not in English, and as you are making the setlocale call with the wrong parameter, you are unable to change the locale. According to this…
-
1
votes2
answers109
viewsA: Error with memcpy and memset
The program is confused, I couldn’t quite understand what it should do, but in relation to the memset the correct is: ... k = malloc(100*sizeof(int)); memset(k, 0, 100*sizeof(int)); ... v =…
-
-2
votes3
answers142
viewsA: Switch locks command when entering a letter
UPDATE Placing here a robust version of the program that has been posted. The root cause of the problem (infinite loop) is a conjunction of 2 factors: the unverification of the "Cin >> R0"…
-
1
votes1
answer430
viewsA: How to use Cmake to compile a project with multiple libraries
For the structure you showed a solution could have 2 Cmakelist.txt files: 1. CMakeLists.txt (na raíz do projeto) 2. src/CMakeLists.txt The first Cmakelists.txt (at the root of the project) might…