Posts by arfneto • 1,196 points
87 posts
-
2
votes1
answer54
viewsA: Change in Array Value
Not so off-topic: URI is University Regional Igraduate, a university of Erechim, RS. Online Judge is a competitive programming platform, or something. This problem is iterative: are N test cases and…
-
2
votes1
answer57
viewsA: Receive more than one value per line with C
There are many ways to read this but I find it always boring. As the matrix is int help a little, and I’ll show you a way. The logic If you didn’t know how many columns there were until the guy…
-
1
votes2
answers48
viewsA: C Language - Read binary file in its full size
sizeof() is an operator, see documentation. The common way to identify the size of a file is to use stat() or use fseek() and ftell(). Using fseek() and ftell() The excerpt below shows the common:…
-
2
votes1
answer38
viewsA: How to pass a list of pointers that references functions as a parameter
See these examples: Case 1: using a pointer vector and size Declare the vector thus: double (*ptrs[])(double) = {f00, f01}; And in function so: void Teste1(int,double (*[])(double)); note that you…
-
0
votes3
answers40
viewsA: How to turn a 2D Array into 2D Pointer in C
I didn’t want to have to change the header of the function findDet(), it is possible to transform my variable of type double A[3][3] in double **A, before passing as parameter to my function? Your…
-
0
votes4
answers409
viewsA: How to transform, for example, "0" to "ZERO" in C? What problem in this code?
About build error already have good answers: you cannot assign values like this in C. int and char[7] with a text representing the int are very different things and there is no direct conversion.…
-
1
votes1
answer49
viewsA: How do I associate a car with a driver in that code that I made
See this set for example: typedef struct { int id; int idade; int telefone; char nome[50]; } Motorista; typedef struct { int id; char marca[50]; char modelo[50]; } Carro; typedef struct { int id;…
-
1
votes5
answers96
viewsA: Matrix with out-of-range index returning correct values
You have good answers above. But I’m going to leave an example in C of this in practice and maybe illustrate these things better I was trying to create a matrix using while and I realized that the…
-
0
votes1
answer40
viewsA: How to insert a Binary Search Tree in C
Maybe you’ll find it easier to read if you write like this: #include <stdio.h> typedef struct st_arv { int info; struct st_arv* esq; struct st_arv* dir; } Arvore; void inserir(Arvore*,int);…
-
2
votes1
answer38
viewsA: Use of delete in an abstract class pointer
I realized that the implementation problem was then in Shape*, that is, a pointer to an abstract class, but I didn’t understand what the problem was The problem is not in Shape nor the fact that it…
-
-1
votes2
answers44
viewsA: Use the class to add the object itself into a vector that stays in another object
I tried to do this same exercise in C++, I’m having difficulty getting the class to add its own object in a vector that stays in the other class and I’m also having some other problems. This data…
-
2
votes1
answer65
viewsA: Problem assigning values to a struct in C
i use a die of type PLATE, however, when calling the value of the plate, my return to plate.letters is the complete given instead of coming only letters, come all and on board.numeros come only…
-
0
votes2
answers44
views -
0
votes1
answer38
views -
0
votes2
answers90
views -
1
votes1
answer52
viewsA: How to shuffle names and colors in C++
This always creates confusion, perhaps because of the way they try to teach it in schools and books. What you want is not to generate random numbers: you want a permutation of the original values.…
-
0
votes1
answer30
viewsA: Doubt on how to read a line in C (sscanf)
sscanf() It wasn’t written for that. It’s to read tabular data, like csv files. If you use a mask with many specifiers --- those things that start with %and not by %%, --- can read a certain number…
-
-2
votes1
answer89
viewsA: How to write a simple chained list in C++ without using <list>?
The code as written has some problems. But on Windows 10 machine I am using worked on gcc and MSVC despite the Microsoft compiler’s uninitialized variable warnings. In RemoveFim() there is no delete…
-
0
votes1
answer41
viewsA: How to assign positions to an array within a "while" loop?
create a program that converts decimal numbers -from 0 to 255 -, which the user types, to binaries. I can already convert normally and show the result reversed, which does not solve. I then thought…
-
1
votes2
answers71
viewsA: How to use comparison function on a Std::Sort
Question 1 What arguments would be receiving parameters x and y? x and y will be 2 instances of Vereador and the function will be called whenever the sort() need to compare two Vereador, with their…
-
1
votes1
answer61
viewsA: find repeated values in the vector in c
About your program int N, tam; scanf("%d", &N); int nums[N]; Do not use this construction. Even if in some case it is possible. In the official state a fixed size or use malloc() and create the…
-
0
votes1
answer50
viewsA: How to identify permutations in matrix columns in C++
C++ and C does not have this notion of matrices as in FORTRAN. There is only vector, and a matrix is a vector vector, or a vector vector vector and so on. In your case dared for example…
-
2
votes1
answer49
viewsA: Add nodes to the chained list using loop
It’s hard to understand with just part of the program what’s going on. Without reading the code of getNode() and the rest of the program becomes difficult. From what posted, it seems very…
-
0
votes1
answer33
viewsA: How to pass char matrix as parameter?
Some time ago I posted something like this, in ONLY and only translated the messages to post again here. The program creates a block of parameters and calls a poor named function :( igual_main()…
-
1
votes1
answer42
viewsA: How do I compare a string that is part of a txt file and another one typed by the user in C?
Compare to this version #include <stdio.h> #include <string.h> int main(void) { FILE *file = fopen("arquivo.txt", "r"); if (file == NULL) { printf("Erro na abertura do arquivo");…
-
-1
votes1
answer48
views -
0
votes1
answer24
viewsA: Function of concatenating two chained lists returning only one element
As I wrote in the comment on the question, I think your program is not as good as the way you wrote it, and I suggest rewriting considering that a list is not a node, a node is not a list, and there…
-
2
votes2
answers48
viewsA: Question in reading and printing names with char
This is the usual: #include<stdio.h> int main (void) { char nome[6]; printf("Qual o seu nome? "); int res = scanf("%5s", nome ); printf( "[scanf() retornou %d]\t", res); if ( res == 1 )…
-
1
votes1
answer43
viewsA: I need to break a string that I receive and I need to divide it. This division will be given to each comma. I’m getting him to recognize the comma
I’m not sure I understand the logic of what you’re trying to do on your show, but it’s something like a scanf() imagine. Whether to read only a table of values and at all times has 6 can use a call…
-
1
votes1
answer37
viewsA: Error assigning malloc to an integer in C language
malloc.cpp: In function 'int main()': malloc.cpp:39:20: error: invalid conversion from 'void*' to 'int*' [- fpermissive] numeros = malloc(n * sizeof(int)); The error may be from the tutorial or…
-
4
votes2
answers56
viewsA: Overload of error operator
You have a good explanation above, but I’ll show you another example, perhaps more complete. Your class is called Ponteiro probably not the best option. whereas she has two int x and y maybe you…
-
2
votes2
answers114
viewsA: I’m doing a c job for college in case anyone can help
Regarding the example with 3 4 6 0 2 9 it is clear that 6 0 2 add up to 8 and it is ok, the sum of all numbers gives 24 so this is the second solution. A third solution is 0 by itself, as would be…
-
1
votes1
answer42
viewsA: Why does the code return error dumped core?
int n, i = 0, j = 0; bool x; bool is_prime(int num) { while(i <= 20) { if(num % i == 0) j++; i++; } if(j > 2) { return false; } else return true; } Don’t write like that. These variables with…
-
0
votes2
answers41
viewsA: Compare strings within C++ file
void comeco(void); void entrar(void); void cad_admin(void); void menu(void); static char inicio, l[15], login[15], senha[7], s[7]; static int i, cont = 0; static string linha; fstream usu,…
-
1
votes1
answer30
viewsA: Invalid conversion when using pointers (invalid Conversion from 'int**' to 'int' [-fpermissive])
struct Inimigo { std::string nome; int vida; }; struct Bloco { int bloqueado_ou_nao; }; struct Mapa { int A; int L; Bloco matriz; }; struct Fase { std::string nome; Mapa mapa_fase; int N; Inimigo…
-
2
votes2
answers76
viewsA: Problem in the scanf, infinite loop
ALWAYS test the return of scanf(). View documentation. scanf() returns a int with the total of served specifiers (specifiers are those things that have one '%' that is not followed by another. In…
-
1
votes1
answer39
viewsA: Write class data in file . dat, and at each use check if the information exists
In general it is not necessary or efficient to use the data directly from the disk. What is done is to read from the disk the set of client actions and keep in memory. At the end of the program, the…
-
1
votes2
answers77
viewsA: Memory allocation with malloc()
This is the malloc prototype() void *malloc(size_t size); And this is what the documentation in Portuguese says in Microsoft Docs about malloc(): size Bytes to allocate And about the value returned…
-
0
votes1
answer45
viewsA: Issue of matrices
So how I was not able to see which numbers repeated in the matrix, I transformed this matrix into a vector[10], and even managed to count which numbers repeat, I just need to put now how many times…
-
1
votes1
answer39
viewsA: How to solve the c variable problem - string capacity, start to grow exponentially from the 3rd cycle
Your program has a lot of problems. I think some things don’t work the way you think. I’ll try to rewrite the program and show you some examples, because I think it might help others. I’ll try not…
-
1
votes2
answers91
viewsA: free() does not work in Dynamic Stack code
Structures like this stack are called C++ containers or java collections, and in the literature they appear as ADT, abstract data structures. And you have to bring your program closer to that, on…
-
0
votes1
answer371
viewsA: How to simulate Stack with chained list in C?
typedef struct stack { int info; struct stack *next; } Stack; /*Função para criar uma pilha vazia (não criar nenhum nó, só devolver NULL)!*/ Stack* create_stack () { return NULL; } These data…
-
3
votes2
answers60
viewsA: Access syntax for data pointer member to class pointer
How do I return the value of x.value using the pptrx "pointer"? I think there is already a good explanation above. But I will repeat next. While doing some pointer tests I came across the following…
-
0
votes1
answer38
viewsA: Remove whitespace excesses from a string
Hello! You have written something like C and not C++. To copy the values to the output string use '+' which is reset to strings and does what you want. temp[p2]= str[p1]; // C, mas temp deve ter…
-
1
votes1
answer128
viewsA: Separate string that has no bounders
I can invent a function like this but if you have any ready library I want to use it In C++, as suggested in this topic and in the answer you quoted, you can use substr() of the string class to…
-
1
votes2
answers135
viewsA: Passing a struct as parameter
it is advisable to keep the structs in main or global scope? Yes, it is advisable and often essential since the whole project will work with them. The general rule is to always use as little scope…
-
3
votes2
answers97
viewsA: Match pointers in C
This code that "got" is not so good. And that didn’t help you much. This title "equalizing C pointers" also makes no sense, especially if we imagine that this is due to this line *max = *min;…
-
0
votes4
answers142
viewsA: Variable value changes in main function
The idea of this exercise was to show the effect of variable scope and the notion of name collision. You can have several x active in your program, and the notion of visibility of a variable ---…
-
0
votes1
answer81
viewsA: Simply Chained List - delete the first half of the list
// (c) Remove the first half of the List. If the list has an odd number of elements, // consider that the first half has more elements // (Ex: if the list has 5 elements, the first half has the…
-
1
votes2
answers129
viewsA: Matrix with C++ Strings
I think you know there’s only three lines here [['3325309756482910474', 'CARRO', '2506794813021649539', '618.57'], ['3325309756485249504', 'MOTO', 2506794813021649539', '649.32'],…