Posts by Lacobus • 13,510 points
596 posts
-
0
votes4
answers7094
viewsA: Swap the first character of a string with the last python character
How about using string slicing to solve your problem: >>> str = "aeiou" >>> str[-1:] + str[1:-1] + str[:1] 'ueioa' Reference:…
-
-1
votes1
answer936
viewsA: Variable not defined Python
You are probably using a Python 2.x interpreter to execute a code written in Python 3.x. In Python 2.x, there were two functions for reading keyboard values: input() and raw_input(), the first reads…
-
6
votes3
answers408
viewsA: Use free() without malloc()?
Here are some observations: 1 - It is good practice to initialize the pointers to NULL when declaring them, a pointer without proper initialization can point to an invalid memory address (dangling…
-
4
votes5
answers163
viewsA: Is there a tool to make html manuals easy to update?
How about the phpDocumentor or the doxygen ?
-
5
votes3
answers1174
viewsA: Conversion of variables type int to char*. C++
How about: #include <stdio.h> char * concatint( char * str, int a, int b ) { sprintf( str, "%d%d", a, b ); return str; } int main ( void ) { char str[ 100 ] = {0}; printf( "%s\n", concatint(…
-
2
votes4
answers118
viewsA: select dinamico
Solution 1 - Using the operator IN: SELECT id, valor, nome_campo, item_id FROM tabela WHERE (nome_campo, valor) IN ( ('campo_1',9), ('campo_2',10) ); Solution 2 - Using logical operators AND and OR…
-
0
votes3
answers257
viewsA: Program executable problem created in c
Following your same line of reasoning, follow a complete and tested solution to your problem: #include <stdio.h> #include <stdlib.h> void exibir_numeros( int numeros[], int qtd ) { int i…
-
9
votes2
answers965
viewsA: Is there any way to run a java program (.jar) from a C or C++ program?
The most standard solution would be using the function system() of the standard library stdlib.h. HOWEVER, from the point of view of systems *nix, the use of system() should be avoided: 1 - The call…
-
1
votes2
answers1523
viewsA: Doubt with DROP COLUMN sql server command
The error message says that the object DF_TB_ESTRACAO_MULTIPLICADOR refers to the column dbo.TB_ESTRACAO.MULTIPLICADOR and so you can not exclude it. The following queries can help understand who…
-
3
votes2
answers79
viewsA: Error in program execution involving pointers
How about using a replacement function to "delete" substrings from a string ? Follow a tested example that solves your problem: #include <string.h> #include <stdio.h> char * strrepstr(…
-
1
votes1
answer338
viewsA: Python Opencv - Error using drawing function
The call of the function cv2.rectangle() is incorrect. The second and third parameters are tuples that represent the coordinates of the opposite vertices of the rectangle that will be drawn in the…
-
1
votes2
answers1017
viewsA: syntax error near Unexpected token `fi' Linux
How about automating the thing in a more robust way: #!/bin/bash STEAM_INSTALL_DIR="steamcmd" STEAM_INSTALLER_URL="https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz"…
-
1
votes1
answer8293
viewsA: C registration system saving in file
How about using the utility gdb to debug your program at runtime ? This is a widely used tool for debugging Leaks memory in large and complex programs. Assuming you’re trying to find the Leak memory…
-
0
votes4
answers14489
viewsA: Invert string in C
Following (tested) solution to the proposed problem: /* reverse.c */ #include <stdio.h> #include <string.h> char * reverse( char * s ) { int length = strlen(s) ; int c, i, j; for (i = 0,…
-
7
votes2
answers503
viewsA: How to hide a string in C, so that it is not readable in compiled code?
This is definitely not good practice. It is a false sense of security to believe that no one will be able to read a data just because it has been stored using a different representation. However, it…
-
1
votes3
answers541
viewsA: Bash - Save errors in a variable
foobar.sh: #!/bin/bash VAR=$(tar -zcf foobar.tar.gz foo.txt bar.txt ) echo "${VAR}" exit 0 Testing: $ ./foobar.sh tar: foo.txt: Cannot stat: No such file or directory tar: bar.txt: Cannot stat: No…
-
9
votes5
answers839
viewsA: How can I add a value to a Row in the comic without having to add variables?
The fastest way I know would be using just one UPDATE: UPDATE tbl_usuario SET vl_saldo = vl_saldo + 50 WHERE id_usuario = 123;
-
3
votes2
answers2762
viewsA: What is the purpose of the void parameter in functions in the C language?
In C, when the signature of a function has only the parameter void means that such function does not receive any parameters when called. There’s a big difference between int foobar(); and int…
-
0
votes2
answers81
viewsA: How to delete the first line of a megaheavy SQL file?
There are several ways to do this on Linux: 1) Using tail (removing first line): $ tail -n +2 arquivo.sql > /tmp/arqtmp.sql; mv /tmp/arqtmp.sql arquivo.sql 2) Using sed (removing first line): $…
-
3
votes1
answer2747
viewsA: Raw Strength Algorithm for Sudoku Game Resolution in C
This method is a brute force algorithm. The advantage of this algorithm is simplicity and its disadvantage lies in the processing time. Therefore, this method is used when simplicity of…
-
1
votes1
answer463
viewsA: read from binary file to linked list c
Here’s an example that might solve your problem: Data structure: #define PERGUNTA_TAM_MAX (256) typedef struct pergunta_s pergunta_t; struct pergunta_s { char pergunta[ PERGUNTA_TAM_MAX + 1 ];…
-
2
votes2
answers549
viewsA: Error while reading C file
Here is a solution to your problem: #include <stdio.h> int main( int argc, char * argv[] ) { FILE * pf = NULL; int n[4]; int i = 0; int linha = 0; int ret = 0; int soma = 0; pf = fopen(…
-
1
votes2
answers719
viewsA: Keyword in String C language
The function strtok() of the standard library string.h is able to 'break' the phrase into words if the token passed is a space. Then, just compare each word of the phrase with the word you’re…
-
5
votes2
answers691
viewsA: Gets() function for float value
Never use the function gets() because it is impossible to tell in advance how many characters will be read, and so, gets() will continue to store read characters beyond the buffer end, which is…
-
2
votes1
answer103
viewsA: Simple code performance improvement in C
Follows a very efficient solution to the problem: #include <stdio.h> #include <stdlib.h> #include <string.h> int parse_data( const char * str ) { int ano; ano = atoi(str); if( ano…
-
0
votes2
answers54285
viewsA: Analyze whether the number is even or odd, and which of the numbers is higher
It is possible to greatly simplify your code, see only: #include <stdio.h> #include <stdlib.h> #define eh_par( n ) ( ( n % 2 ) ? 0 : 1 ) #define comparar( a, b ) ( ( a == b ) ? 0 : ( ( a…
-
0
votes4
answers3023
viewsA: Rand between numbers with comma
The following program illustrates how to draw values double using the function rand(): #include <stdio.h> #include <stdlib.h> #include <time.h> #define MIN (-270.33f) #define MAX…
-
2
votes1
answer107
viewsA: How to separate an array of pairs into sets?
The proposed problem can be solved with an algorithm called Flood Fill. Important points to consider: 1) Implement a search algorithm (BFS or DFS) to traverse the graph nodes; 2) For each…
-
1
votes2
answers680
viewsA: Hibernate jumping id sequence
Probably this Identifier is being generated by backend (Postgresql). This phenomenon happens because the SEQUENCES in Postgresql are resistant to ROLLBACKs within transactions. Probably the…
-
1
votes1
answer154
viewsA: Reset repeated values of a matrix
The secret is to create a vector of integers with 10 positions int cont[ 10 ], each position shall be an independent counter for each number (from 0 to 9). Follow the solution tested and commented:…
-
1
votes2
answers9106
viewsA: Remove array element in C
Follow the complete solution of customer registration using static vector: /* cadastro.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define ERRO_CADASTRO_CHEIO…
-
5
votes5
answers1698
viewsA: How can I ask the user for confirmation in a bash file?
The parameter -n 1 causes the command to read wait for the typing of only one character, without the need to press enter. The command read has a default return variable called $REPLY, by specifying…
-
0
votes4
answers1177
viewsA: How not to repeat terms on printf
The secret is the creation of a vector x able to map the repetitions and even their frequency. 1) Solution - Mapping the repetition of vector values a in the vector b: #include <stdlib.h>…
-
1
votes1
answer122
viewsA: Read elements from a file
To read and store large integers, I suggest using character vectors char[], this way you have the flexibility to work with numbers with n number of digits. Follow the necessary modifications to your…
-
5
votes5
answers13398
views -
0
votes3
answers280
viewsA: Make a shell script bash that extracts to a new file all names and nr of women whose number starts with "91"
Only awk v1: $ awk 'BEGIN{FS=";"}{if($2=="Feminino" && index($4,"93")==1) print $1,$4}' ficheiro1.txt Only awk v2: $ awk -F";" '$2=="Feminino" && $4~/^93/ {print $1,$4}'…
-
1
votes1
answer2608
viewsA: Sort stack items A and B on stack C
Follows the (tested) solution of the problem using sorting bubble sort nonrecursive: /* ****************************************************************** */ /* * pilha.c * */ /*…
-
0
votes2
answers86
viewsA: Problem with dynamic allocation of bidimencional matrices in C
There is a conceptual error here: Pointers to pointers are not two-dimensional matrices. Although they are accessed in the same way using the subscriber operator [], the way the memory was allocated…
-
1
votes1
answer1450
viewsA: Manipulating batteries in C
Following is a (tested) solution to the proposed exercise, the logic is basically the same as its code: /* ****************************************************************** */ /* * estacionamento.c…
-
2
votes1
answer177
viewsA: How to calculate the download time of a website using wget?
Using the curl: $ curl -so /dev/null -w '%{time_total} segs\n' http://melga.com.br/ Using the time and wget: $ time wget -q -o /dev/null http://melga.com.br/ I hope it helps!…
-
2
votes1
answer1899
views -
1
votes2
answers5028
viewsA: How to put each line of a txt file into a vector?
Follows a solution using only fscanf(): #include <stdlib.h> #include <stdio.h> int main( int argc, char * argv[] ) { FILE * pf = NULL; int idade = 0; char nome[10] = {0}; char…
-
3
votes2
answers276
views -
1
votes2
answers350
viewsA: Doubt in string, and comparison
Function strstr() standard library checks if one string is contained in the other, there is no need to reinvent the wheel: #include <stdio.h> #include <stdlib.h> #include…
-
1
votes1
answer560
viewsA: Get ID of a process
In linux, if there is no standard way to get PID from a process from its name, an interesting approach is to scan the directory /proc searching for all process-related Pids: #include…
-
3
votes4
answers16290
viewsA: How to remove spaces from a string in C?
Characters representing blank spaces can be tested using the function isspace() of the standard library ctype.h. The secret is to scan the input string, character by character, and if the read…