Posts by pmg • 6,456 points
254 posts
-
2
votes1
answer100
views -
0
votes1
answer554
viewsA: Error 5% URI C - 1047 - Minutes Play Time
Your solution is quite complicated. Makes normal difference (end time - start time) then adjusts if necessary #include <stdio.h> void deltaHM(int *h, int *m, int hi, int mi, int hf, int mf) {…
-
0
votes2
answers98
viewsA: Warning: format '%f' expectts a matching 'double' argument (en)(en)
The function printf() is a function with variable argument number (with ... in the prototype). Thus, the arguments fall under the domain of ... suffer the preset promotions for arguments (link in…
-
1
votes1
answer332
viewsA: Count number of lines in the file
Your problem is the definition of "line". Normally a line is defined by "a sequence of (0 or more) characters terminated by, and including, one end-of-the-line". In some cases it can also be defined…
-
2
votes1
answer48
viewsA: ESP8266 Node MCU receiving commands in JSON
Your main problem (no longer searched) is in the function str_to_char(). You are creating a local variable in that function with the name strAux. This variable ceases to exist once the function…
-
0
votes2
answers78
viewsA: Doubt [MEDIA PROBLEM]
If you have the maximum (ie 10000 values equal to 1000000) the sum (10000*1000000 = 10000000000) exceeds the limit available in 32 bits (2147483647). The guy signed long int is not necessarily…
-
0
votes2
answers2032
views -
2
votes1
answer155
viewsA: Time Limit Exceeded
Checks the amount returned by scanf() if (scanf("%d%d%d", &X, &Y, &P) != 3) exit(EXIT_FAILURE); if (scanf("%d", &Q) != 1) exit(EXIT_FAILURE); if (scanf(" %c", &carac) != 1)…
-
0
votes2
answers84
viewsA: Form with Struct and Pointers
void recebe (struct Pessoas *y) { fflush (stdin); fgets (y->nome, 30, stdin); fgets (y->endereco, 50, stdin); scanf ("%d", &y->telefone); } Don’t mix fgets() and scanf() void recebe…
-
0
votes2
answers144
viewsA: Operation of function scanf()
It returns the number of assignments made to facilitate error handling. Imagine that you should read a date (format yyyy-mm-dd), a temperature value and, optionally, a rainfall value. For example…
-
1
votes1
answer37
viewsA: Pass RGB pixels from a file to C Structure
How do I do that? To read lines from file: uses fgets() To convert string text into integers: uses strtoul() To assign values to variables: uses =…
-
0
votes1
answer559
viewsA: Request for Member 'name' in Something not a Structure or Union - Error
//scanf("%s",&p->nome); scanf("%9s", p[i]->nome); Note that the sexo no room for the terminator ('\0') string.
-
1
votes3
answers45
viewsA: Pointer positioning
In the second cycle while the first exchange puts '\0' at the first position of the string, effectively leaving the empty string. Assuming the user input "foo". Just before the while cycle the…
-
0
votes1
answer166
viewsA: Use of Enum within a Struct
Instr is a guy. You have to define a object (a variable) of this type to assign a value. Instr foo; // foo não inicializado Instr bar = {0}; // bar inicializado com zeros Instr baz = {ATTRIB,…
-
3
votes2
answers191
viewsA: difference between vet[] and *vet
What’s the difference between void funcao(int vet[]) { /* ... */ } and void funcao(int *vet) { /* ... */ }? Absolutely none. The two shapes are 100% identical. Note that in C, it is impossible to…
-
0
votes1
answer50
viewsA: Can anyone help me find what is causing a build error in the code?
Your code is correct for recent versions of C since C99. In C89 (apparently the C that is used on the site in question), it is not possible to use the variable statement within the for // válido em…
-
3
votes2
answers342
viewsA: Doubts about the realloc function
By reducing the reserved space to exemplo for 3 bytes, the content of these 3 bytes is 'T', 'e', 's' (notes especially the absence of '\0'), that is, this content no longer gives a string. As you…
-
0
votes1
answer95
viewsA: struct problem
You are forgetting the space needed to finish the strings. char matricula[7]; // espaço para "12ff12" e terminador
-
4
votes1
answer1787
viewsA: How to create multiple . txt files?
In C, you can, for example, loop in which you generate different filenames. If you always create a file with the same name, the Operating System will only save the latest file. #include…
-
4
votes1
answer265
views -
1
votes2
answers112
viewsA: What’s wrong with my Quicksort code in C?
So at first glance I detected two errors (I did not compile or run your code): the b has to go backwards while (tabela[b] > pivo) { // b = b + 1; // OOPS b = b - 1; } and to call the function…
-
0
votes1
answer110
viewsA: In the C language, I cannot work properly with a matrix
You cannot define arrays with zero elements; neither with constant values (in C89), nor with VLA (in C99). char a1[0]; // declaracao C89 (C99, C11) invalida int size = 0; char a2[size]; //…
-
1
votes1
answer56
viewsA: SIGSEGV error in using a pointer
void FileLer(char *texto, char *file) { // ... ret = GEDI_FS_FileRead(FileHandleLer, &texto, &BufferLenLer); // ^^^^^^ // ... } &texto and texto are different things. The first has kind…
-
0
votes3
answers82
viewsA: Should I allocate the member of the date structure as well?
When you allocate space to an object of the type struct lnode you are allocating space to all its members (two pointers and an integer). Each of these members is not initialized; that is, the value…
-
0
votes1
answer65
viewsA: Create dynamic structures from a text file?
The while(!feof(fm)) is wrong (see this question in the English OS). What happens is that the function feof() does not indicate if the next reading will give error, it indicates if the last error…
-
1
votes1
answer550
viewsA: How to pass the field of a struct to a function in a library separately?
With the definition of struct in the main program the library has no information about it. You have to put the definition of struct itemDeLista in a file that both "sources" have access to; for…
-
4
votes1
answer90
viewsA: What’s wrong with my show?
printf("INICIO:%p\n", &dn->dnh.inicio); printf("FIM:%p\n", &dn->dnh.fim); The printed values above are addresses of dn->dnh.inicio and dn->dnh.fim. To print content (pointer…
-
4
votes2
answers464
viewsA: Tip for C code optimization
Instead of passing the array elements one by one, pass the array (converted to a pointer for the first element) and its size at once. switch (recebido) { case 'A': saida_completa(dadoA, sizeof dadoA…
-
4
votes2
answers503
viewsA: How to hide a string in C, so that it is not readable in compiled code?
To "hide" the string you can apply the rot13 #include <string.h> // para strchr() // aplica rot13 a src e mete o resultado em dst // se dst nao tiver tamanho suficiente invoca UB // devolve…
-
1
votes1
answer46
views -
6
votes2
answers194
viewsA: How to read the command line?
You want to get the result of system() within your program? Usa POSIX popen() or MSDN _popen() #include <stdio.h> #include <stdlib.h> int main(void) { FILE *handle; char cmd[] = "dir";…
-
3
votes2
answers180
viewsA: Why does the statement "char *argv[]" work in the main rg, but not in the body of the code?
Why the statement char *argv[] works in the main Arg, but not in the body of the code? Because (Standard 6.7.6.3p7) parameter declaration as "type array" will be adjusted to "pointer to type" ...…
-
1
votes1
answer208
viewsA: Program.exe has stopped working
for(i=0, j=0;nomecompleto[i]!=' '&&nomecompleto!='\0';i++) //aqui ele pega todos os caracteres do nome completo, até achar um espaço ou o limitador // ^^^^^^^^^^^^^^^^^^ nome1[j++] =…
-
0
votes1
answer224
viewsA: Error Segmentation fault (core dumped) in read and break string code
Your immediate problem is in education free(valor); valor = malloc(40); for (...) { valor = strtok(...); // OOPS, "memory leak" } free(valor); // OOPS, não podes fazer free // a uma memória que não…
-
3
votes3
answers11758
viewsA: When to use const and when to use #define
There are some situations where you cannot use objects (variables with const) #define XPTO 42 const int xpto = 42; switch (valor) { case XPTO: // OK case xpto: // erro } int arraynormal[XPTO]; // OK…
-
2
votes4
answers6903
viewsA: Generate random numbers that do not repeat
An efficient way to generate random numbers without repetition is to store all numbers in an array, shuffle that array, and then select the amount of numbers desired. #define RANGE 1000000 #define…
-
1
votes1
answer630
viewsA: Vector sorting of character vectors with qsort <stdlib. h>
Wrong qsort(equipe[j], qtd_membros, sizeof(char*), cmpstr); // ^^^^^^^^^^^^^ The array equipe has such a size sizeof (char) * 50 * 5000 * 1000 (the same as sizeof equipe). Each element of this array…
-
2
votes1
answer48
viewsA: Why do I get QNAN error when I calculate this?
The function media() does not have an instruction of return!
-
2
votes1
answer98
viewsA: C - Double popping size
The functions q7() and q8() has no instruction to return! double q7 (double index) // Turbidez { double a = 97.34, b = -0.0139, c = -0.04917; printf("Turbidez\n"); if ( index > 100) return 5.0;…
-
3
votes2
answers102
viewsA: Function calculates to a certain extent and to
In function calcSoma() the value you add to s becomes smaller and smaller much quick. numerador / fatorial(valFat) is a number increasingly close to zero. 1.367879 + 0.0000000000000....0006576423…
-
0
votes1
answer81
viewsA: Find path of a file only given the name
If you are in a POSIX system you can use the ntfw function(). Or write a recursive function that scans a directory for the file.…
-
1
votes2
answers345
viewsA: FWRITE function is not writing in binary format in C language
The contents of type objects struct registro is basically just text. No wonder the contents of the file are characters. Check the part of ano_lancamento in the file "Games.dat". How would you like…
-
0
votes1
answer4866
viewsA: How to add or remove a vector element?
You cannot remove an element from a vector. Imagine that the vector is like a parking lot and its places. You can’t remove a place, you can just change the content of each place. An approximate…
-
0
votes2
answers627
viewsA: Calculation in program C results in zero in any calculation value
printf("seu consumo e:%.2f \n", &calc); // omite & para valor ^ assim é endereço de memória The correct form is printf("seu consumo e:%.2f \n", calc);…
-
0
votes2
answers331
viewsA: Is there any way I can change the range of the Rand function in the middle of the C code?
Changes the srand() out of the cycle. Change the statement that has the rand() to consider minimum and maximum values, for example using, minval and maxval to calculate the number intermedio (use…
-
0
votes2
answers1809
viewsA: How to return to the menu after performing function?
The simplest solution is // ... int main() { for (;;) menu(); }
-
2
votes1
answer1856
viewsA: Count rows and null columns of a matrix
As indicated in a comment by Pablo Almeida, try to separate the code into differentiated pieces (functions), each doing one thing. For example, like this: #include <stdio.h> #include…
-
1
votes3
answers103
viewsA: C pointers, error calling the relocation function
Conflicting types for ːalocarEspaco' You have a function prototype (defined before, probably in a #include) signature other than the one used in the definition.…
-
1
votes1
answer103
viewsA: Processes - Doubt
After the fork() (if no error) there are two distinct variables with name value. One this in the original process (with value 9), another is in the child process (also with value 9). the if (pid ==…
-
4
votes3
answers747
viewsA: Is malloc typecast recommended?
It is not recommended to do the cast to the outcome of malloc() for the compiler to indicate the missing error of the #include <stdlib.h>. As the compiler has no information about the type of…