Posts by Lacobus • 13,510 points
596 posts
-
2
votes3
answers2408
views -
0
votes1
answer401
viewsA: Convert an entire string to Sqlite
Assuming your Structure is similar to the following: CREATE TABLE tab_lancamento ( id_lancamento integer, id_categoria integer, tipo_lancamento character varying(1) ); CREATE TABLE tab_categoria (…
-
1
votes5
answers1202
viewsA: How to perform a task at a precise time in time?
In C: #include <stdio.h> #include <time.h> #include <unistd.h> void callback_func( time_t t ) { printf("CallBack: %ld\n", t ); } void timer( int intervalo, void (*func)(time_t) ) {…
-
1
votes1
answer136
viewsA: Vectors and Matrices
How about: #include <stdio.h> #define sizeof_array(a) (sizeof(a)/sizeof(a[0])) void decifrar( int matriz[], int tam ) { int i = 0; for( i = 0; i < tam; i++ ) printf( "%c", 'A' - 7 +…
-
0
votes2
answers117
viewsA: Return records that total desired value
Surely your problem can be solved by Window Functions. Here is an example based on your question: Structure: CREATE TABLE staging_livro_razao ( num bigint, fornecedor text, debito real, credito…
-
2
votes1
answer41
viewsA: Function for matching points
Your reasoning is correct and can be implemented in other ways: Using ternary operators: int pontoCoincide( Ponto P, Ponto Q ) { return (P.x == Q.x && P.y == Q.y) ? 1 : 0; } Or simply: int…
-
2
votes3
answers1589
viewsA: How to read file line . txt from index 0
If the intention is to read line by line a text file filtering the contents of each line by removing double spaces by single spaces, follow 2 solutions in C++ using the STL: Using the functions…
-
3
votes2
answers6147
viewsA: Concatenate columns into a single Postgresql row
Structure: CREATE TABLE public.foobar ( Codigo BIGINT, Descricao TEXT ); Dice: INSERT INTO public.foobar( Codigo, Descricao ) VALUES ( 1, 'Descricao 1' ); INSERT INTO public.foobar( Codigo,…
-
1
votes1
answer317
viewsA: printing memory junk
Follows a program capable of meeting the problem statement in a very clear and efficient way using dynamic memory allocation. Note that each function is responsible for a part of the task and have…
-
0
votes1
answer120
viewsA: SQL to notify a confirmed date 2 days before the same in Sqlite
How about: sqlite> SELECT date( 'now', '+2 day') >= date('2017-06-24'); 1 Explanation: If today’s date is 2017-06-22 is the +2 dias date of registration tested (in case: 2017-06-24), the…
-
2
votes1
answer4013
viewsA: Binary file storage
You are opening the file in binary mode for recording (wb), but is not recording content correctly... The recording and reading of the data shall be done with the functions fwrite() and fread()…
-
2
votes6
answers1851
viewsA: Interlink two strings into one vector
How about a specific function for your case: #include <stdio.h> #include <stdlib.h> #include <string.h> char * intercalar( char * s, const char * a, const char * b ) { int i = 0;…
-
1
votes2
answers512
viewsA: Error creating child - Process scheduling using Fork
How about a generic function capable of solving the problem: void fork_children( int count, int delay ) { int i = 0; int j = 0; pid_t pid = 0; for ( i = 0; i < count; i++) { sleep(delay); pid =…
-
2
votes1
answer447
viewsA: Generate PPM file
Based on its original program, I wrote an experimental program capable of generating images in the format .ppm containing color gradients. Note that the functions red(), green(), blue(), gray() and…
-
2
votes2
answers7809
viewsA: How to create postgresql tables using automatic primary key id generation?
In Postgresql the AUTO_INCREMENT is at all times made by means of SEQUENCES. When using the numeric type BIGSERIAL, an object of SEQUENCE is created implicitly by the server. Serial and bigserial…
postgresqlanswered Lacobus 13,510 -
0
votes4
answers7433
viewsA: Reverse vector position/value
Follows a copy capable function by reversing the contents of one array of integers to another: #include <stdio.h> #include <string.h> #define sizeof_vector(v) (sizeof(v) / sizeof(v[0]))…
-
1
votes2
answers3199
viewsA: How to return a char vector to a function in C? type as a pointer
Following its original rationale, follows an example (tested) of how to concatenate and return each message contained in another vector of pointers (messages): #include <stdio.h> #include…
-
1
votes1
answer2102
viewsA: C ordering using recursion
SELECTION SORT It is a simple algorithm that takes up little memory and is quite efficient if sorting small volumes of data. It is extremely slow to order large volume of data, its complexity will…
-
2
votes2
answers36
views -
3
votes4
answers4690
viewsA: Caesar cipher - problem with letters and spaces
On the basis of Article wikipedia, implemented the functions of cifragem and decifragem from a chave, represented by an integer value. Note that encryption and decryption only consider letters,…
-
6
votes3
answers138
viewsA: Is it possible to use for loop to reduce C code?
How about something like this: void functionX( unsigned int buf ) { int i; int addr[16] = { EEPROM_A15, EEPROM_A14, EEPROM_A13, EEPROM_A12, EEPROM_A11, EEPROM_A10, EEPROM_A9, EEPROM_A8, EEPROM_A7,…
-
2
votes1
answer519
viewsA: Record screen with ffmpeg
How about: $ ffmpeg -f x11grab -s 1280x720 -r 25 -i :0.0 -q:v 5 video.mkv Where: $ ffmpeg -f x11grab -s <Resolucao> -r <Quadros Por Segundo> -i :0.0 -q:v <Qualidade de Video 1-5>…
-
5
votes4
answers224
viewsA: Code Optimization / Image Processing
Follow another solution using a "static" mapping of neighbors' coordinates: int masc[4][2] = { {1,1}, {1,0}, {1,-1}, {0,1} }; for( altura = img->altura - 2; altura >= 0; altura-- ) { for(…
-
2
votes3
answers281
viewsA: Problem with pointer and recursive function
How about: Node * search( Node ** root, int mats ) { Node * n = *root; Node * e = NULL; /* verifica o fim da arvore */ if( !n ) return NULL; /* verifica o noh atual */ if( n->person.mat == mats )…
-
2
votes2
answers1061
viewsA: Most odd number
Counting the amount of odd numbers in an integer vector: #include <stdio.h> #include <stdlib.h> /* Macro para calcular quantidade de elementos dentro de um vetor */ #define…
-
0
votes2
answers528
viewsA: Postgres-case when
Your aggregation logic with the sum and the coalesce seems to me to be incorrect. Try to replace: coalesce(sum(valor),0) as pendencia For: sum(coalesce(valor,0)) as pendencia But if you still prefer…
postgresqlanswered Lacobus 13,510 -
0
votes2
answers1031
viewsA: Divide vector according to delimiters and copy content to other strings in C
How about using the function strtok() of the standard library string.h? Follow (tested) example of a code similar to yours: #include <string.h> #include <stdio.h> #define MAX_TAM (256)…
-
1
votes2
answers5533
viewsA: Return string in C for manipulation outside the function in which it was declared
Here are some options for your case: Option 1 - The client allocates a buffer and passes its pointer as parameter to be filled in internally by the function: #include <stdio.h> #include…
-
2
votes1
answer199
viewsA: Wrong return of ping command
Error code returned by utility ping may vary depending on the occurrence: Success: 0 Timed-out: 1 Unreachable Host: 2 So, it follows example (tested) of a script capable of solving your problem:…
-
1
votes1
answer694
viewsA: Identify memory leak in c++?
Here is a list of free tools capable of checking memory at runtime (Runtime) and point out where the probable Leak: 1) Dr. Memory: http://code.google.com/p/drmemory/ 2) UMDH:…
-
2
votes1
answer90
viewsA: Notification on a local network with Postgresql
No Postgresql(Versao >= 9.1) you can make use of the pair LISTEN/NOTIFY to do something like this. These functions enable bank-connected clients to receive asynchronous notifications through a…
-
2
votes2
answers47
viewsA: Find data not registered in postgres
Assuming your table has the following structure: CREATE TABLE tb_ano_mes ( id bigserial, ano int, mes int, CONSTRAINT pk_ano_mes PRIMARY KEY ( id ) ); Containing the following data: INSERT INTO…
-
20
votes3
answers13759
viewsA: Difference between %i and %d
The conversion specifiers %i and %d are interpreted in the same way by the functions of the family fprintf(), however, they are interpreted differently by the function family of the fscanf(). Both…
-
0
votes3
answers797
viewsA: Count numbers 1 in binary number after decimal base conversion
The algorithm capable of solving the proposed problem is known by several names: Hamming Weight, Population Count, popcount or Sideways Sum. Wikipedia has an excellent article talking deeply on the…
-
4
votes2
answers7943
viewsA: How to write a full number in C Language?
Here is an example of code (tested) capable of displaying the number in full in Portuguese. #include <stdio.h> #include <string.h> #include <stdlib.h> static const char *…
-
1
votes1
answer80
viewsA: How to create a robot to test traffic on my site on localhost?
How about using the Apachebench? For example: $ ab -n 100 -c 5 http://www.google.com/ -n: Specifies the number of HTTP requests. -c: Indicates amount of simultaneous HTTP connections. Exit: This is…
-
2
votes2
answers2767
viewsA: Determining a string within a C switch
Here are 3 ways to solve the problem without using a table of constants. 1) Char pointer for constant string: #include <stdlib.h> #include <stdio.h> int main( int argc, char * argv[] ) {…
-
3
votes2
answers574
viewsA: Postgresql query without data return
This happens because field datavenda table vendas is the type timestamp, your query is being interpreted as follows: SELECT * FROM venda ve WHERE ve.datavenda <= '28/08/2016 00:00:00.000000';…
-
2
votes1
answer374
viewsA: Improve search performance when there is no record
Use of the clause is not recommended LIKE for textual searches in tables with a large volume of data. It is recommended to use a Postgres resource called FTS (Full Text Search). Follow a…
-
1
votes2
answers73
viewsA: Stack does not remove values
Following its rationale, it follows a simplified (and tested) code that implements a stack LIFO of values float. /* ****************************************************************** */ /* *…
-
1
votes1
answer459
viewsA: Validate google key api
Assuming the key has exactly 39 Size characters; Consists of alphanumeric characters (letters and numbers), in any case (uppercase or lowercase); And may have dashes - and underlines _. Follow the…
-
5
votes1
answer850
viewsA: How to encode and decode Base64 strings in C?
Avelino, don’t judge a code by its matrices! The example you found is based on the file ap_base64.c of the project APR - Apache Portable Runtime (see here the original code), which in turn is quite…
-
2
votes1
answer608
viewsA: How can I automatically format equations in Word 2013?
LaTex is a standard and very widespread solution for what you want. However, in the short term, how about generating/capturing an image of the equation and inserting it directly into your document ?…
-
5
votes2
answers1014
viewsA: How can we get the execution time of a script?
The function microtime() returns the timestamp current. You can use it to "mark" the initial time and the end of your script in order to obtain the execution time. Follow an example: <?php //…
-
1
votes2
answers186
viewsA: Convert File Names to Alphabet Letters
Follow solution tested for the problem: #/bin/bash n=0 alfabeto=$(echo {A..Z}) find . -maxdepth 1 -name '*.jpg' -type f | while read imagem; do mv "${imagem}" "${alfabeto[n++]}.jpg" done exit 0…
-
0
votes1
answer426
viewsA: How to change the size of a global structure vector in C?
Here are two possible solutions to your problem: 1) Solution with dynamic vector allocation with functions malloc() and free() of the standard library stdlib.h: #include <stdlib.h> typedef…
-
3
votes2
answers758
viewsA: Average between timestamp dates
Follows a solution using window functions: SELECT cadastro.data AS data, EXTRACT(EPOCH FROM cadastro.data) - lag(EXTRACT( EPOCH FROM cadastro.data)) OVER (order by cadastro.data) AS intervalo FROM (…
postgresqlanswered Lacobus 13,510 -
4
votes1
answer146
viewsA: How to encrypt a C-drive?
Here are some tips and suggestions: 1) It is not just because information cannot be read in an orthodox way (through common operating systems) that it is safe. This is called falsa sensação de…
-
1
votes2
answers3959
viewsA: Problems with UTF8 in postgres
Assuming the coding of your DATABASE and your server are using the UTF8 as ENCODING, I suggest checking with your client. Postgresql has an environment variable called CLIENT_ENCODING which is…
-
3
votes3
answers1514
viewsA: Search between dates with between
The record is not returned because the field age_data_agendado_para is the type datetime and the dates passed in your BETWEEN are of the type date. So your SELECT can be read as follows: SELECT *…