Posts by Lacobus • 13,510 points
596 posts
-
2
votes1
answer164
viewsA: Break string with multiple symbols
Unfortunately, the function strtok() is not able to interpret two tokens followed as a "null field". One solution would be to implement another version of strtok() capable of behaving exactly the…
-
1
votes1
answer1631
viewsA: How to delete components from an image using python?
You can 'reset' the color channels independently as follows: # Removendo canal AZUL img[:,:,0] = 0 # Removendo canal VERDE img[:,:,1] = 0 # Removendo canal VERMELHO img[:,:,2] = 0 Here is an example…
-
1
votes3
answers10296
viewsA: How to read a string with C++ space inside a function
You can use the function std::getline() combined with the function std::ignore(). The function std::getline() is able to read input until a new line is detected while std::ignore() clears the new…
-
1
votes3
answers1051
viewsA: Identify a numerical sequence in a text file
You can use the module glob to recover a list containing the name of all the files .txt in a given directory. By iterating on this list, you can open each of the files, reading only the first line…
-
0
votes2
answers36
viewsA: Separating using + signal while reading user data
You can use the formatting operator %, for example: i = 1 textos = [] texto = input("Digite o texto %d (aperte enter para sair):" % (i) ) Or else you can use the method format(), for example: i = 1…
-
2
votes3
answers4284
viewsA: Problem with special character "ç" in javascript
You can use a UNICODE escape sequence \u to represent the ç and the Ç: \u00e7 is equivalent to ç (minuscule) \u00c7 is equivalent to Ç (capital) For example: alert('mar\u00e7o');…
-
0
votes2
answers1225
viewsA: How to check if the txt file has a blank space on the last line
If the intention is to work with text files, there is no reason to open the input and output files in binary mode. Follow a tested solution capable of "concatenating" all files with extension .txt…
-
1
votes2
answers153
viewsA: SQL - Insert that receives calculated values from other columns of other tables
Assuming your structure and your data are something like: CREATE TABLE tb_vendas ( id SERIAL, id_produto INTEGER, valor_venda REAL, quantidade INTEGER ); CREATE TABLE tb_produto ( id INTEGER, nome…
postgresqlanswered Lacobus 13,510 -
2
votes1
answer328
viewsA: Problems Reading C File - Comma Delimiter
You can use the function strtok() of the standard library string.h to "break" the line into fields. The following function is able to split the string src, using the delimiter delim and return it in…
-
1
votes2
answers335
viewsA: How to add multiple dictionaries using pickle to save to txt
You’re just copying a reference from your dictionary. To make a identical duplicate from your dictionary use the function deepcopy() module copy: import copy ... escola[aluno['nome']] =…
-
1
votes2
answers190
viewsA: How can I print a string instead of char?
First you declare a array pointer strings: char * fc[2] = { "Cara", "Coroa" }; Then one of the pointers contained in array: char * comp = fc[ rand() % 2 ]; To display the string from the drawn…
-
3
votes1
answer171
viewsA: Functions with parameters in c language
You need to go through all the elements of the vector, storing in an auxiliary variable the index that contains the highest value ever found, for example: #include <stdio.h> int intMax( int…
-
1
votes1
answer303
viewsA: How to make a pointer point to NULL?
You can include a flag indicator of NULL in each of the cells in its matrix, for example: #include <stdlib.h> typedef struct CELULA { int is_null; double valor; } CELULA; typedef struct…
-
2
votes2
answers875
viewsA: Decode data in Base64
To 'decode' a data represented in base64 you can use the function b64decode() module base64 as follows: import base64 b64 = 'TyByYXRvIHJvZXUgYSByb3VwYSBkbyByZWkgZGUgUm9tYQ==' print…
-
1
votes3
answers196
viewsA: Is it possible to store values without using static vectors?
You can allocate one array of pointers (lines), each pointing to a array of CELULAS (columns). Illustrating the idea: Follow a tested and commented code demonstrating a possible solution: #include…
-
3
votes3
answers5645
viewsA: What is the purpose of declaring a function within a function?
Don’t confuse métodos de classe with funções. It is not possible that a Método de Classe contains another Método de Classe declared within its scope. Métodos de Classe are at all times associated…
-
1
votes3
answers942
viewsA: Number greater than 7 in a Python list
You can use the function sum() combined with a Expressão Geradora to obtain the number of items in a list that have a value higher than 7: a = [5, 10, 6, 8] print sum( i > 7 for i in a ) Exit: 2…
-
2
votes2
answers1296
viewsA: Is it possible to add more than one item to a list at once?
You can use the operator += to concatenate one list into another: a = [] a += ['abóbora', 'banana', 'maçã'] print(a) Exit: ['abóbora', 'banana', 'maçã']…
-
0
votes1
answer760
viewsA: Arrays and Pointers
The GCC is returning a warning saying that the pointer int *ptr is being initialized with a type that is not a ponteiro para um inteiro. In fact, that’s exactly what you’re doing because v, in the…
-
2
votes2
answers254
viewsA: "Deep Copy" without importing the "copy" module?
From the @jsbueno user response, I was able to better understand the complexity of the subject I’m dealing with. After many tests and different approaches, finally I arrived at the following code:…
-
1
votes1
answer37
viewsA: Failed to read formatted file via incoming redirect
The problem with your code is that fscanf() cannot identify special end-of-line character \n, causing your while do not insert correctly on the input lines. You can read line by line from your input…
-
1
votes1
answer175
viewsA: Problems with scanf and printf in C++
In C++, try to avoid the use of functions printf() and scanf()! They can be perfectly replaced by std::cout and std::cin, respectively. The same happens with strings, instead of using a pointer…
-
2
votes1
answer336
viewsA: Python - How to add add values between row and column in ndarray
To solve your problem, a dicionário of listas would be more appropriate than a NumPy array, look at you: lista = [('Sao', 'V'), ('Paulo', 'NPROP'), ('18', 'N'), ('de', 'PREP'), ('julho', 'N'),…
-
3
votes2
answers1186
viewsA: How do I resolve these libpng errors in pygame?
This is about a Warning issued by libpng. Means the image file PNG that you are using possesses Chunks iCCP invalid. To remove the Chunks invalid of an image PNG, you can use the utility convert…
-
4
votes1
answer660
viewsA: Problems with Gaussian filter application
The code of your question is an image processing algorithm called Filtro Espacial. Filtragem Espacial refers to the image plane, involves direct manipulation of the image pixels using a Máscara…
-
0
votes2
answers772
viewsA: How to use a dynamically allocated vector returned from a function in C?
Your program is "closing" before displaying the result as it is causing a segmentation failure. This error occurs when a program attempts to access (read or write) an address in memory that is…
-
1
votes2
answers451
viewsA: Semantic difference of "Malloc" and Calloc"
The name calloc() is certainly an abbreviation of clear-allocation, equator malloc() comes from memory-allocation. However, the dynamic allocation functions of the standard library stdlib.h have…
-
0
votes1
answer55
viewsA: Shell script detect Aps and Mac Address
You can use the utility iwlist with the argument scan to list all Aps within range: $ sudo iwlist wlan0 scan Exit: wlan0 Scan completed : Cell 01 - Address: 00:1F:F3:02:04:81 ESSID:"Apple Network"…
-
4
votes1
answer1083
viewsA: How to add the numbers of a column in the bank that has the same id and repeats?
Assuming your model and your data are something like: CREATE TABLE produto_venda ( venda_id INTEGER, prod_id INTEGER, prod_unidade INTEGER ); CREATE TABLE produto ( prod_id INTEGER, prod_nome TEXT,…
-
0
votes1
answer50
viewsA: Code doesn’t do multiplication. What am I doing wrong?
Instead of using fgets() combined with atoi(): char svalor[10]; fgets(svalor, 10, stdin); removerNL(svalor); int valor = atoi(svalor); You can simply use scanf(): int valor; scanf("%d", &valor);…
-
4
votes2
answers423
viewsA: Identify string between two known snippets in a string
You can build a finite state machine with only 2 states to solve your problem: def pesquisar( seq, inicio, fim ): estado = 0 ret = [] aux = [] for x in seq: if estado == 0: if x == inicio: aux = [ x…
-
2
votes1
answer109
viewsA: False error opening decrypted document with Python Crypto library 2.7.9
AES is an algorithm of block cipher, and works with fixed size blocks of 16 bytes or 128 bits, no more, no less. This means that your implementation should take some factors important under…
-
2
votes1
answer463
viewsA: Create 90-day filter before a period
How about: SELECT * FROM TABELA WHERE DT_INICIO_REAL BETWEEN to_date('01-OCT-2017') and to_date('10-OCT-2017') AND (trunc(sysdate) - DT_INICIO_REAL) >= 90; See working on Sqlfiddle…
-
2
votes3
answers6982
viewsA: Calculate the standard deviation of a vector
Consider the following set containing 10 amostras: { 2, 3, 3, 4, 5, 6, 7, 8, 9, 10 } First, we calculate the simple arithmetic mean of the samples from the assembly: We then calculate the deviation…
-
5
votes1
answer411
viewsA: How to do a query in sql that returns data from a table when the data is empty?
Beware! There is great confusion when you say that a certain value is "empty". The term "empty" may be referring to different things: null content [NULL]; blank content [length(s) == 0]; content…
-
1
votes1
answer735
viewsA: Losing image quality while resizing in pygame
To avoid this quality loss, you can use the method pygame.transform.smoothscale() to resize the image with a special filter Smooth. In the example below we used a image in format PNG with…
-
3
votes1
answer205
viewsA: Implement Triggers in Postgre
If the tables mentioned do not undergo operations of UPDATE, surely a TRIGGER would not be necessary to solve your problem. You can change the columns of all tables containing the date/time by…
-
2
votes2
answers566
viewsA: Select values that are not in another table
Assuming your structure and your data are something like: CREATE TABLE fila ( id INTEGER, idlinks INTEGER, usuario INTEGER, url TEXT ); CREATE TABLE atividade ( reg INTEGER, usuario INTEGER, acao…
-
3
votes1
answer401
viewsA: Query to sum query total
Assuming your table structure and your data are something like: SET DATESTYLE = DMY; CREATE TABLE payments ( person_id INTEGER, payment_status_id INTEGER, amount_paid REAL, created_at TIMESTAMP );…
-
1
votes1
answer353
viewsA: Sql in Postgresql: Do Not Repeat Values from a Table field
The tables receipt_status and receipts are not necessary in that query, they do not relate to any other table and none of their fields are recovered! I couldn’t see how to calculate the "paid…
-
3
votes2
answers984
viewsA: Simulate keyboard typing programmatically in c
Assuming your keyboard is on /dev/input/event3, follows a code capable of "simulating" the typing of the command ls -al followed by a enter: #include <stdio.h> #include <unistd.h>…
-
1
votes1
answer373
viewsA: Ungroup code in one line
You’re certainly looking at a code minificado. To demystify it, you will need a program known as desminificador, code beautifier or Prettyprint. That one website has a code "beautifier" javascript…
-
1
votes3
answers268
viewsA: Select postgres between two values
Assuming you have a structure like this: CREATE TABLE ( id BIGINT, id_cliente BIGINT, taxa_devolucao REAL ); INSERT INTO tb_devolucao ( id, id_cliente, taxa_devolucao ) VALUES ( 1, 100, 1.25 );…
-
3
votes1
answer1722
viewsA: Is it possible to create 3d games with pygame?
The module pygame of Python is based on libsdl. Known as Simple Directmedia Layer or SDL. SDL is not a 3D graphical library. According to the information contained in official page: SDL is a…
-
1
votes1
answer131
viewsA: I need to match a string matrix to another matrix, how do I do?
You can use the function strcpy() of the standard library string.h to copy each of the strings contained between the arrays two-dimensional texto[][] and string[][]. Never use the function gets()!…
-
1
votes1
answer297
viewsA: psqlodbca.so: Cannot open shared object file: File or directory not found
Seems to me you don’t own the driver ODBC Postgres installed on your system. You can do this using the package manager apt-get: $ sudo apt-get install odbc-postgresql Or manually download the…
-
0
votes1
answer361
viewsA: Function showing list in reverse order
There is nothing wrong with the logic of your program, it works exactly as you described it: it displays the values contained in the nodes of a chained list iterating from the last node toward the…
-
3
votes2
answers1345
viewsA: Change Boolean column to integer
Assuming that your table OS be something like: CREATE TABLE OS ( ID INTEGER, STATUS BOOLEAN ); INSERT INTO OS ( ID, STATUS ) VALUES ( 100, TRUE ); INSERT INTO OS ( ID, STATUS ) VALUES ( 200, FALSE…
-
7
votes2
answers254
viewsQ: "Deep Copy" without importing the "copy" module?
Is there any other way to perform a "Deep Copy" of Python objects without using method deepcopy() of the standard library copy ? The code below could be written differently ? import copy class Xpto:…
-
14
votes4
answers359
viewsA: Output a C code with pointers
Follow your commented code: #include <stdio.h> int main() { int i = 5; /* Atribui 5 ao inteiro 'i' */ int *p; /* Declara um ponteiro 'p' para inteiro */ p = &i; /* Atribui ao ponteiro 'p'…