0
I am creating a stack for valid expression check, but it should be used in this int main( int argc, char **argv )
for input. I compiled and did not make a mistake, but I cannot create an executable file through the prompt. And I’ve already forced the creation of one through devc++, but when I do the terminal test the program stops working. I’ve tried to put the argument in simple quotes but the program is also killed that way.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TNOME 100
struct nodoPilha {
char nome [TNOME];
struct nodoPilha *proximoPtr;
};
typedef struct nodoPilha NodoPilha;
typedef NodoPilha *NodoPilhaPtr;
void imprimePilha( NodoPilhaPtr atualPtr );
int ehVazia( NodoPilhaPtr headPtr );
void pop( NodoPilhaPtr *headPtr );
void push( NodoPilhaPtr *headPtr, char nome[TNOME] );
int main( int argc, char **argv ){
NodoPilhaPtr headPtr = NULL;
int h;
char *aux;
int i = 1;
while (i < argc){
i++;
h = ehVazia(headPtr);
if (h){
push (&headPtr, argv[i]);
aux = argv [i];
}
else {
if (aux != argv [i]){
pop (&headPtr);
char aux;
}
else {
push (&headPtr, argv [i]);
}
}
}
if (h){
printf ("Valida");
}
else {
printf ("Nao Valida");
}
}
void push( NodoPilhaPtr *headPtr, char nome[TNOME] ){
char * novalinha = strchr(nome, '\n');
if (novalinha)
*novalinha = '\0';
NodoPilhaPtr newPtr;
newPtr=malloc(sizeof(NodoPilha));
if ( newPtr != NULL ) {
newPtr->proximoPtr = *headPtr;
strcpy( newPtr->nome,nome);
*headPtr = newPtr;
}
else {
printf( "%c nao foi inserido. Memoria nao foi disponibilizada.\n", nome );
}
}
void pop( NodoPilhaPtr *headPtr ) {
NodoPilhaPtr tempPtr;
tempPtr = *headPtr;
*headPtr = ( *headPtr )->proximoPtr;
free( tempPtr );
}
int ehVazia( NodoPilhaPtr headPtr ){
return headPtr == NULL;
}
void imprimePilha( NodoPilhaPtr atualPtr ){
NodoPilhaPtr inicioPtr;
inicioPtr=atualPtr;
if ( atualPtr == NULL ) {
puts( "Pilha esta vazia.\n" );
}
else {
puts( "A pilha eh:" );
while ( atualPtr != NULL ) {
printf( "%s --> ", atualPtr->nome );
atualPtr = atualPtr->proximoPtr;
}
puts( "NULL\n" );
}
}
How are you making the call? Error occurs?
– ℛɑƒæĿᴿᴹᴿ