Compare commits
No commits in common. "master" and "1.0.0" have entirely different histories.
6
Makefile
6
Makefile
@ -1,6 +1,5 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -Wextra -Wpedantic -O2 -std=c99
|
||||
LDFLAGS=-lm
|
||||
CFLAGS=-Wall -O2
|
||||
|
||||
ifndef VERBOSE
|
||||
.SILENT:
|
||||
@ -8,8 +7,7 @@ endif
|
||||
|
||||
all: clean resistormaid
|
||||
|
||||
resistormaid: resistormaid.c
|
||||
$(CC) $(CFLAGS) resistormaid.c -o resistormaid $(LDFLAGS)
|
||||
resistormaid: resistormaid.o
|
||||
|
||||
clean:
|
||||
rm -f resistormaid *.o
|
||||
|
@ -1,16 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
int16_t value = 0;
|
||||
int16_t sixDigit = 0;
|
||||
float tolerance = 20;
|
||||
float multiplier = 0;
|
||||
int8_t multiplier = 0;
|
||||
int16_t sixDigit = 0;
|
||||
int8_t hasThirdValueBand = 0;
|
||||
int8_t k,m,g = 0;
|
||||
|
||||
int colorValues(char *colorInput) {
|
||||
if(!strcmp(colorInput, "black")) return 0;
|
||||
@ -76,7 +73,6 @@ int main(int argc, char **argv) {
|
||||
goto exit;
|
||||
}
|
||||
value = firstDigit * 10 + secondDigit; // handles argv[1] and argv[2]
|
||||
|
||||
if(numargs > 4) {
|
||||
hasThirdValueBand = 1;
|
||||
int8_t thirdDigit = colorValues(argv[3]); // handles argv[3]
|
||||
@ -94,7 +90,7 @@ int main(int argc, char **argv) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(numargs > 3) { // handles argv[4] and argv[5]
|
||||
if(numargs > 3) { // handles argv[5]
|
||||
tolerance = toleranceValues(argv[4 + hasThirdValueBand]);
|
||||
if(tolerance == -1) {
|
||||
if(hasThirdValueBand) printf("Invalid fifth argument! Exiting now.\n");
|
||||
@ -103,22 +99,6 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
multiplier = pow(10.0, multiplier);
|
||||
float output = value * multiplier;
|
||||
|
||||
if(output >= 1000.0) {
|
||||
k = 1;
|
||||
output = output / 1000;
|
||||
}
|
||||
if(output >= 1000.0) {
|
||||
m = 1;
|
||||
output = output / 1000;
|
||||
}
|
||||
if(output >= 1000.0) {
|
||||
g = 1;
|
||||
output = output / 1000;
|
||||
}
|
||||
|
||||
if(numargs > 5) { // handles argv[6]
|
||||
if(!strcmp(argv[6], "black")) sixDigit = 250;
|
||||
else if(!strcmp(argv[6], "brown")) sixDigit = 100;
|
||||
@ -136,23 +116,8 @@ int main(int argc, char **argv) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
char stringOut[16]; // remove the unnecessary '.' and '0' characters
|
||||
sprintf(stringOut, "%.2f", output);
|
||||
int8_t counter = strlen(stringOut) - 1;
|
||||
int8_t exitTracker = 0;
|
||||
while(stringOut[counter] == '0' || stringOut[counter] == '.') {
|
||||
if(stringOut[counter] == '.') exitTracker = 1; // so we stop after the dot
|
||||
stringOut[counter] = '\0';
|
||||
counter--;
|
||||
if(exitTracker) break;
|
||||
}
|
||||
|
||||
printf("%s", stringOut);
|
||||
if(g) printf("G");
|
||||
else if(m) printf("M");
|
||||
else if(k) printf("K");
|
||||
|
||||
printf(" Ohm +-%g%%", tolerance);
|
||||
printf("%i 10^%i +-%g%%", value, multiplier, tolerance);
|
||||
if(sixDigit != 0) printf(" %ippm", sixDigit);
|
||||
printf("\n");
|
||||
exit:
|
||||
|
Loading…
Reference in New Issue
Block a user