0
Hello, today I bring here a question related to data structures that surely can add in the understanding of all envovilido. It is a matter of pile manipulation where through the act of traversing this pile one tries to form "diamonds" represented by "<" and ">" forming "<>" while ignoring "." that here represents gravel.
The problem is that I’m having several incompatibility problems every time I work on this topic so I think I’m doing something fundamentally wrong. This will be my definitive post on the topic and maybe here I can remedy the most diverse questions related
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
struct mine{
char mining[1000];
int num_minings;
int top;
int left_side, right_side, full_diamond;
}mine;
void mining_cases(struct mine mine){
printf("Digite o numero de mineracoes/n");
scanf("/p%d" &mine.num_minings);
int aux = mine.num_minings;
while(aux != NULL){
miner(mine.mining);
aux -=1;
}
void miner(struct mine mine){
printf("iniciando minerador.../n");
scanf("%c",&mine.mining);
while( mine.mining!= "\0"){
if(mine.mining == "<"){
++mine.left_side;
}
if(mine.mining == ">"){
++mine.right_side;
}
if (mine.left_side == mine.right_side){
mine.full_diamond = mine.right_side;
}
if (mine.left_side != mine.right_side && mine.right_side > mine.left_side){
mine.full_diamond -= (mine.right_side - mine.left_side);
}
if (mine.left_side != mine.right_side && mine.left_side > mine.right_side){
mine.full_diamond -= (mine.left_side - mine.right_side);
}
}
void main(struct mine mine){
mining_cases(struct mine mine);
}
Here’s the list of mistakes I’m having:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
||In function 'mining_cases':|
|14|error: invalid operands to binary & (have 'char *' and 'int')|
|16|warning: comparison between pointer and integer|
|17|warning: implicit declaration of function 'miner' [-Wimplicit-function-declaration]|
||In function 'main':|
|43|error: expected expression before 'struct'|
|In function 'miner':|
|45|error: expected declaration or statement at end of input|
|In function 'mining_cases':|
|45|error: expected declaration or statement at end of input|
||=== Build failed: 4 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
Without going into the aspects of your code but meet the concept of "stack", on a stack you only have access to the top of the stack and the operations allowed are to add an element in the stack (push) and remove the top element of the stack (pop). If you consider that you are treating your Mining array as a stack then you are wrong.
– anonimo
As for your code to operate with strings you have to use the <string functions. h>. This:
scanf("%c",&mine.mining);
has no meaning sincemining
is a character array and not a single character. Use orscanf("%s", mine.mining);
orscanf("%c",&mine.mining[i]);
, as well asif(mine.mining[i] == '<'){
or the functionstrcmp
. Study on arrays and pointers.– anonimo