Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include "string_me8.h"
- #include "get_input.h"
- char input[60];//Remember to always reset
- int boolean = 1;//Never off.
- int get_bool_input(){
- int x = 0;
- input[0] = '\0';
- do{
- fgets(input, 60, stdin);
- clean_fgets(&input);
- if(strcmp(input,"y")==0||strcmp(input,"Y")==0){
- x = 1;
- break;
- }else if(strcmp(input,"n")==0||strcmp(input,"N")==0){
- x = 0;
- break;
- }else{
- input[0] = '\0';
- }
- }while(boolean==1);
- return x;
- }
- //Getting Input for Topology ==============================================================
- int get_topology(){
- //Variable Declaration & Initialization
- int topology;
- //Getting Input for Topology
- input[0] = '\0';
- do{
- printf("Please select the topology of the circuit:\n\t1 - Series Circuit\n\t2 - Parallel Circuit\n\t3 - Ladder Circuit\n\n");
- fgets(input, 60, stdin);
- clean_fgets(&input);
- if(strcmp(input,"1")==0||strcmp(input,"2")==0||strcmp(input,"3")==0){
- break;
- }else{
- input[0] = '\0';
- }
- }while(boolean==1);
- topology = atoi(input);
- return topology;
- }
- //Getting Input for Source Type ==============================================================
- int get_source_type(){
- //Variable Declaration & Initialization
- int source_type;
- //Getting Input for Source Type
- input[0] = '\0';
- do{
- printf("Please select the type of Independent Source:\n\t1 - Voltage Source\n\t2 - Current Source\n\n");
- fgets(input, 60, stdin);
- clean_fgets(&input);
- if(strcmp(input,"1")==0||strcmp(input,"2")==0){
- break;
- }else{
- input[0] = '\0';
- }
- }while(boolean==1);
- source_type = atoi(input);
- return source_type;
- }
- //Getting Input for Value of Source ==============================================================
- double get_source_value(){
- //Variable Declaration & Initialization
- double source_value;
- //Getting Input for Value of Source
- input[0] = '\0';
- do{
- printf("Please input value of the source:\n\tNote: The maximum value should be 1000000.00,\n\t\tThe minimum value should be -1000000.00,\n\t\tand it cannot be zero.\n\n");
- fgets(input, 60, stdin);
- clean_fgets(&input);
- source_value = atof(input);
- if (source_value == 0){
- continue;
- }else if(source_value<-1000000.00){
- continue;
- }else if(source_value>1000000.00){
- continue;
- }else{
- break;
- }
- }while(boolean==1);
- return source_value;
- }
- //Getting Input for Resistor Number ==============================================================
- int get_resist_no(){
- //Variable Declaration & Initialization
- int resist_no;
- //Getting Input for Resistor Number
- input[0] = '\0';
- do{
- printf("Please input the number of resistors:\n\tNote: The maximum number of resistors is 100,\n\t\tThe minimum number of resistors is 1.\n\n");
- fgets(input, 60, stdin);
- clean_fgets(&input);
- resist_no = atoi(input);
- if (resist_no == 0){
- continue;
- }else if(resist_no<1){
- continue;
- }else if(resist_no>100){
- continue;
- }else{
- break;
- }
- }while(boolean==1);
- return resist_no;
- }
- //Getting Resistor Values ==============================================================
- double get_resist_value(){
- //Variable Declarations
- double placeholder;
- int i;
- //Geting Resistor Values
- input[0] = '\0';
- do{
- fgets(input, 60, stdin);
- clean_fgets(&input);
- if (strcmp(input, "Infinity")==0||strcmp(input, "infinity")==0){
- placeholder = INFINITY;
- break;
- }else if (strcmp(input, "0")==0){
- placeholder = 0;
- break;
- }else{
- placeholder = atof(input);
- printf("DEBUG: Placeholder: %.6f\n", placeholder);
- if(placeholder<=0.0){
- printf("E: Invalid Resistance!\n\tPlease re-input value of Resistor #%d: ",i+1);
- continue;
- }else{
- break;
- }
- }
- }while(boolean==1);
- return placeholder;
- }
- // Getting Individual Resistor Values ==============================================================
- void get_individual_resistor_values(int integerArray[], double doubleArray[]){
- /*List of indexes
- intArray
- 0 - topology
- 1 - source_type
- 2 - resist_no
- 3+resist_no - resistor_values
- doubleArray
- 0 - effective_resistance
- 1 - effective_voltage
- 2 - effective_current
- 3 - source_value
- */
- //Placeholders
- int indecs = 0;
- double y = 0.0;
- // Getting Individual Resistor Values
- input[0] = '\0';
- printf("Type \"exit\" to stop at any time.");
- do{
- printf("\n\tPlease input Resistor #: ");
- fgets(input, 60, stdin);
- //printf(input);//debug
- clean_fgets(&input);
- indecs = atoi(input);
- if(strcmp(input, "exit"==0)||strcmp(input, "Exit"==0)||strcmp(input, "EXIT"==0)){
- break;
- }else if(indecs<=0||indecs>integerArray[2]){
- printf("E: Invalid input. Please try again.");
- continue;
- }else{
- print_indie_values(integerArray,doubleArray,indecs);
- }
- }while(boolean == 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement