I should develop a calculator that reads strings from the algebraic form of the operation with complex numbers. I need to manipulate the "main" vector outside the function in which it was declared (receives). How to proceed? Should I use pointers? How to use them?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int tam_max = 256;
int recebe(){
int i = 0;
int erro = 0;
char principal[tam_max];
char real1[tam_max];
setbuf(stdin, NULL);
fgets(principal, tam_max, stdin);
for (i = 0; i < strlen(principal); i++){
if (principal[0] == '\n'){
erro++;
} else if ( principal[i] == '+' || principal[i] == '-' ||
principal[i] == '*' || principal[i] == '/' ||
principal[i] == '=' || principal[i] == '^' ||
principal[i] == 'i' || principal[i] == 'p' ||
principal[i] == '0' || principal[i] == '1' ||
principal[i] == '2' || principal[i] == '3' ||
principal[i] == '4' || principal[i] == '5' ||
principal[i] == '6' || principal[i] == '7' ||
principal[i] == '8' || principal[i] == '9' || principal[i] == '\n'){
erro == 0;
} else {
erro++;
}
}
return erro;
}
int validaDados(){
int verifica = 0;
verifica = recebe();
if (verifica > 0){
printf("\nCaracteres invalidos inseridos. Por favor, tente novamente.\n\n");
validaDados();
}
if (verifica == 0){
divide();
}
}
int divide(){
printf("OK ate aqui\n");
}
int main(){
validaDados();
}