2
I must develop a calculator that reads strings in the algebraic form of the complex number operation. I need to manipulate the "main" vector outside the function in which it was declared (receives). How to proceed? Should pointers be used? 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();
}
Want to return what? Will use this return as? The code does not indicate what you want and there is no description in the question of what should be done. Need to give details.
– Maniero
@bigown I need to return the "main" vector to manipulate it outside the scope in which it was declared (receives()). Later this vector will be modified within another function. My difficulty is manipulating strings of each scope without declaring them globally.
– 01010000