Posts by Fábio Morais • 1,522 points
59 posts
-
1
votes2
answers88
viewsA: How can I split a string by semicolon and take the value of each position after the while?
Can declare a multi char array result[5][10] where there are 5 lines of strings that can have a maximum length of 10 characters in each line. This is a very siples example, can also dynamically make…
-
4
votes3
answers450
viewsA: Comparison of Vector regardless of position
The correct way to compare 2 vectors is to take the i position of the 1st vector and compare with all the positions of the 2nd vector. for(i = 0; i < 3; i++){ for(j = 0; j < 3; j++){…
canswered Fábio Morais 1,522 -
0
votes2
answers1331
viewsA: write struct to file
The fwrite() should be replaced by fprintf(ptr, "%s %d %f", pessoa.nome, pessoa.idade, pessoa.altura); Just use the Wordpad and you can see how it’s going. With fprintf you can choose how you want…
-
0
votes1
answer64
viewsA: Time to send data
The way it has is to use the delay(), only that the problem is that using it the program is stopped, so the only way is to use the timers, start a timer for 10s, when the timer ends (pass the 10s)…
-
0
votes0
answers90
viewsQ: Sum all values in a column and group every 2 minutes
I wanted to add up all the values every 2 minutes and group those same values valor tempo 0.3 2019-05-22 01:11:45---> first value 0,3 0.3 2019-05-22 01:12:16-----| 0.3 2019-05-22…
-
0
votes1
answer196
viewsA: Is it possible to open the file for writing and at the same time open for reading without before closing in C?
It is good practice to close every time you open a text file. With the attached table you can see some features you can implement to read and write. These functions below are used to read and write…
-
0
votes0
answers32
viewsQ: Vector memory allocation of int inside a struct
My structures are defined this way: typedef struct{ Medicoes *medi; unsigned int numeroMots;//comprimento de mots diferentes, nao repete int *mots;//MOTS existentes na room int compMots;//omprimento…
casked Fábio Morais 1,522 -
1
votes0
answers42
viewsQ: Allocate dynamic memory with multiple strings
My goal is to allocate memory "down", making a genre of an array, in which the string length is static Maxlength and the number of strings that is placed is used dynamic memory. #define MaxLength 35…
casked Fábio Morais 1,522 -
3
votes1
answer248
viewsA: Highest value in a fixed vector of 10 positions
You are sending the value of v[0] for the variable maior, without even defining some value for it, soon goes a value that can not control. Imagine that v[0] has the value of 403234, when writing…
-
1
votes1
answer34
viewsA: Doubts about strings
You can use the scanf or the fgets, the most "famous" and that serve perfectly to read a sentence instead of a word. Scanf: You’ll have to add the [^\n], to accept all characters except the enter…
canswered Fábio Morais 1,522 -
4
votes2
answers767
viewsQ: Difference between local variable VS global variable
In my micro controller classes the variables are always defined globally and very rarely locally and I would like to know why, because in my mind it makes a difference between being global or local.…
-
3
votes1
answer619
viewsA: What is the difference between %d and %i in printf and scanf in C?
Are interpreted equally in printf, choose whichever you prefer. In the scanf is that things are different. The %d only recognizes numbers of base 10 The %i accepted octal (prefix 0) and hexadecimal…
canswered Fábio Morais 1,522 -
1
votes1
answer704
viewsA: (C) Make an algorithm that reads a string and removes vowels and whitespace
int i = 0, x=0; printf ("Insira uma string:\n"); fgets(str, 999, stdin); while (str[i] != '\0') { if (str[i] == 'a'||str[i] == 'e'||str[i] == 'i'||str[i] == 'o'||str[i]== 'u' || str[i] == 'A'||…
-
0
votes1
answer1955
viewsA: How do I ask the user to type the vector size?
int main(){ int x=10; int valor[x]; } It’s the same thing as doing int main(){ int valor[10]; } Or using define // #define x ValorPredefinido #define x 10 /** EXEMPLO, caso saiba que será esse valor…
canswered Fábio Morais 1,522 -
2
votes1
answer169
viewsA: How do I overwrite a string with another accent without?
Accents not supported in table ascii, therefore the origin of this whole problem is therefore impossible to do. But you can use this example below do the prints debug, as input put something like…
-
3
votes2
answers1821
viewsA: How to implement a queue using two stacks
typedef struct item_p { int elemento; struct item_p *proximo; } pilhaItem; typedef struct { pilhaItem *raiz; int tamanho; } pilha; pilha* pilha_nova() { /* cria pilha */ pilha *p = (pilha*)…
-
3
votes2
answers2007
viewsA: Concatenate Strings in C
I made the basic idea of the program and I will explain the logic, however this program fails in some cases that I will say too, will have after having some validations for this code to work for the…
-
3
votes1
answer75
viewsA: Difficulty in ordering
His problem was in the Selection Sort was doing a bad algorithm implementation. You must have an extra variable max, because when trading the name with index i I don’t know if I’m explaining it…
-
2
votes1
answer71
viewsA: How to print only once the name repeated?
An alternative to solve this problem is to create a new variable nomes_repetidos in which it stores the repeated names, if it does not yet exist, for this it takes a function that searches in the…
canswered Fábio Morais 1,522 -
2
votes2
answers78
viewsA: Doubt if Else returning 0
valortotal=valormor+valormac; valormor and valormac is only initialized with a value below, you should then change that line valortotal=valormor+valormac; to the end. if (qmor<=5)…
-
7
votes1
answer743
viewsA: Accept uppercase and lowercase character
You can use the function toupper and convert the sn uppercase then put something like : if(sn=='S') Thus, if the user writes s will convert to S, write S maintains. That is, this way you can either…
-
0
votes1
answer1875
viewsA: How to use abs() in an if function, Else if (c)
abs(int x) this function returns the absolute value of x. Case xnegative, return positive. Case x positive, return positive. x=abs(x); //basta esta linha para converter `x` para positivo else if…
canswered Fábio Morais 1,522 -
2
votes1
answer675
viewsA: Multiply n numbers in c
What’s happening is that by typing the 0 it will multiply by multi and so the result is 0 do { printf("Digite um valor"); scanf("%d",&val); // ao inserir 0 multi= multi*val; // multi= multi * 0…
canswered Fábio Morais 1,522 -
3
votes1
answer103
viewsA: Binary tree printing only left side
Looking only at the function prints and assuming that the other functions are well implemented can repair that it does not give return in the function of printing. void preOrdem(Arvore *arv){…
-
2
votes1
answer896
viewsA: C / How to calculate the average in this program?
To struct must be defined outside the main if you want to use for other functions. typedef struct { int n; int cpf; int idade; float altura; } Pessoa; int main(){ ... } Inside the main- Can only be…
canswered Fábio Morais 1,522 -
0
votes2
answers1292
viewsA: What’s best to use, scanf() or get_s()?
char nome[25]; scanf(" %24[^\n]s", nome); You can do it this way, the most important thing is to limit the scanf as in this example, if you remove the 24 and the user enters a name greater than 24…
-
0
votes1
answer165
viewsQ: Print memory available in C
How to know the amount of memory available before doing the malloc()? I would like to print the memory value that is still available in order to be allocated, the code has to run on Windows and…
-
2
votes2
answers412
viewsA: Remove elements from the end of a list in C
First the printing function is wrong, the way it is doing is messing with the original list, ie while doing p=p->proximo you move up the list, then you miss the beginning of the list. You must do…
canswered Fábio Morais 1,522 -
2
votes1
answer807
viewsQ: Stable vs unstable sorting
What defines a stable sort algorithm? In this question has already been talked a little about what is stable and unstable ordering, but I still do not understand the advantage of using an unstable.…
-
1
votes2
answers85
viewsA: Segmentation Fault with malloc()
scanf("%ld %ld", &n1, &n2); int *vetor; vetor = malloc(abs(n2 - n1+1) * sizeof(long int)); for ( k = 0; k <= abs(n2-n1); k++) { vetor[k]=0; } I think I wanted to do it this way, we need…
-
1
votes2
answers4332
viewsA: How to identify a line break character in C?
int number; char nl = 0; while ( scanf("%d%c", &number, &nl) != EOF) { printf("%d \n", number);//debug if (nl == '\n') break; } It’s an example that I think will work, I put a print to give…
-
2
votes1
answer428
viewsQ: Read a number starting with 0
I’m having trouble reading a number initialized with long long long long valid; scanf("%lli", &valid); Input: 025 The variable valid will have as content 21 and not 25 If I change %lli for %llu…
-
1
votes2
answers128
viewsA: If Else Statement problems chained in C language
If you debug the program you will find that if(30.0<Imc<34.9) is always true, that is, that is not the way you will have to do it. In C you have to make the comparison this way: if(Imc<34.9…
-
5
votes1
answer1694
viewsQ: Torque calculator in C
I have this function that converts decimal to binary, but then how do I sum the bits, or use the & (and), etc. ? Use the operator & do we have to count to 2 decimal places? Ex: 25 & 25…
-
-2
votes2
answers302
viewsA: When I run the commands on Switch Case, does it end instead of going back to Menu?
To return to the menu would need a cycle or even use the function drop, when using a cycle had to put off the switch And it’s only when I press key seven that I’m out of that cycle. The break makes…
-
1
votes1
answer42
viewsA: Ordering With a certain condition
if(pessoa[i].nota > pessoa[j].nota) { aux = pessoa[i].nota; pessoa[i].nota = pessoa[j].nota; pessoa[j].nota = aux; strcpy(a, pessoa[i].nome); strcpy(pessoa[i].nome, pessoa[j].nome);…
-
2
votes1
answer135
viewsA: scanf does not stop at a loop
Just put a space in the scanf(" %[^\n]", texto); because you need to clean the buffer before reading again, otherwise it reads once and then never reads the other word again
canswered Fábio Morais 1,522 -
0
votes2
answers242
viewsA: Code::Blocks does not print pointer value
int x=5; int *p; p = &x; printf("O valor de X e: %d\n", *p); printf("O valor de X e: %d\n", p); The first printf() prints the value of x, the second prints the address of the pointer. All your…
-
5
votes2
answers3921
viewsA: puts() and printf(), when and which to use?
The two functions are equal, but the function puts() adds a line break equal to printf("\n") But when using the puts() we have to be aware that only prints the string, we do not have control of the…
-
1
votes2
answers2791
viewsA: How to turn a character into an integer in C?
Can use a cast, example: char c='a'; printf("%d", (int) c); tutorialspoint To convert the character '0' -> 0, '1' -> 1, etc char c = '5'; int i = c - '0';…
-
4
votes2
answers106
viewsA: Function with a pointer?
while (var < 0 || var > 10) In this case you want to validate (*var), when placing var is using the address The correct answer would be while ((*var) < 0 || (*var) > 10) As we make:…
-
0
votes2
answers522
viewsA: Infinite loop on switch
Obviously it will be endless loop, off the switch is the while(true) without any kind of break, just take it out that solves the problem. You can also add the break; after the switch if you want to…
-
10
votes2
answers930
viewsQ: Prototype functions in C/C++
What kinds of functions are these? What can these prototypes do? /*1*/int func ( int (*x)(int,int) ) /*2*/int func ( int x(int,int) ) /*3*/int func1 ( int(fn)() ) /*4*/int func2 ( int(*fn)() ) Is…
-
7
votes2
answers7494
viewsQ: Handling of malloc() and realloc()
I still don’t feel completely confident about using the malloc() or realloc(), these two ways are equivalent? 1) int main() { int x=0; char *s2,*s1; s1=NULL; s2=malloc(200); while(x++<3) {…
-
1
votes2
answers451
viewsA: How to give 'value' to a char variable?
char str[6]="maria"; Is that? maria has 5 characters, but has to book +1 because of the ' 0', so we reserve 6 of static memory
-
2
votes2
answers82
viewsA: Why does this code give Segmentation fault?
I think you want to do it this way: /* Alocação dinamica relativamente à parte da linha*/ char **map = (char **) malloc((sizeof(char*) * x)+1); /* Alocação dinamica relativamente à parte da coluna*/…
-
0
votes2
answers1096
viewsA: How to count how many substrings you have in a C string?
You can use the function strstr(), this function checks the existence of a substring in a string, then just count the number of characters it has in the substring comparing to the string, or also…
-
4
votes1
answer313
viewsQ: C/C++ standard libraries
What’s the downside of using libraries standards such as the function getch() and the library conio.h, What is the downside of using such libraries from a development point of view? More precisely…
-
0
votes2
answers155
viewsA: Doubt about char in C
char directionX Allows only one character, for example 'c', 'a'...etc char *directionX It is basically a char pointer that has no static memory. char directionX[20] It is the same as the previous…
canswered Fábio Morais 1,522 -
1
votes2
answers183
viewsA: Value Assignment Doubt in c
By doing b++ or ++b you are moving the variable b It is different than doing value+=b, in this case only moves the variable "value"