Compare commits

..

10 Commits

Author SHA1 Message Date
Nicolás A. Ortega
b9e7bb6b7d
Need an extra line there. 2016-07-13 22:22:40 +02:00
Nicolás A. Ortega
aaa653afcd
Added travis to README.md 2016-07-13 22:21:28 +02:00
Nicolás A. Ortega
147fc10bd8
Removed a couple problematic flags. 2016-07-13 22:13:05 +02:00
Nicolás A. Ortega
bf76b4a911
Added a build file.
Hope this works...
2016-07-13 22:07:15 +02:00
Nicolás A. Ortega
1685ecc1e9
Removed the binary (it was a test.) 2016-07-12 15:40:25 +02:00
Nicolás A. Ortega
c33919a3c6
Adding a temporary windows binary. 2016-07-08 20:01:33 +02:00
Nicolás A. Ortega
ecd4980ba2
Now reads a file and obtains its numbers. 2016-07-08 18:26:04 +02:00
Nicolás A. Ortega
e9bd5bcdd0
Now parsing commandline arguments. 2016-07-07 20:45:57 +02:00
Nicolás A. Ortega
156f8de5c0
Strict compiler with reldeb default build. 2016-07-04 16:17:16 +02:00
Nicolás A. Ortega
597fc22124
Added to the README.md 2016-07-04 12:52:40 +02:00
5 changed files with 152 additions and 16 deletions

13
.travis.yml Normal file
View File

@ -0,0 +1,13 @@
# Define the language
language: c
addons:
apt:
packages:
- build-essential
- cmake
script:
- cd build/
- cmake -DCMAKE_BUILD_TYPE=Release ..
- make

View File

@ -1,13 +1,17 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
project(MMMCalc) project(MMMCalc)
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic-errors") if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra -Werror -Wfatal-errors -Wmissing-declarations -pedantic-errors")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O3") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O3")
set(CMAKE_C_FLAGS_MIN_SIZEREL "${CMAKE_C_FLAGS} -Os") set(CMAKE_C_FLAGS_MIN_SIZEREL "${CMAKE_C_FLAGS} -Os")
set(SRCS set(SRCS
src/Main.c) src/main.c)
add_executable(mmmcalc ${SRCS}) add_executable(mmmcalc ${SRCS})

View File

@ -1,5 +1,10 @@
MMMCalc MMMCalc
======= =======
[![Build Status](https://travis-ci.org/Deathsbreed/MMMCalc.svg?branch=master)](https://travis-ci.org/Deathsbreed/MMMCalc)
MMMCalc is a program I made after school one day after having to learn about Mean, Median, and Mode for the thousandth time. So instead of doing my actual homework I decided to make this program which would do it for me. Of course, the program with this is that your teachers often ask you to show your work. Well, fear not! For MMMCalc shows you **its** work. After it does its calculations, if you turn on _verbose mode_ (by using the `-v` argument) it will show you how MMMCalc got to that answer that it's giving you. After going through Mean, Median, and Mode (the reason why this program is called **MMM**Calc) I decided to add a few other basic statistical properties to it.
I hope this helps someone to make their millionth time of doing Mean, Median, and Mode in school a little less of a pain in the ass.
### Compiling ### Compiling
MMMCalc uses [CMake](http://cmake.org/) to compile. Please install the C development tools and CMake (along with whichever build script you plan on having CMake generate) in order to run this command. MMMCalc uses [CMake](http://cmake.org/) to compile. Please install the C development tools and CMake (along with whichever build script you plan on having CMake generate) in order to run this command.

View File

@ -1,14 +0,0 @@
#include <stdio.h>
// 0 = false;
// 1 = true;
char version[16] = "v0.5";
int verbose = 0;
int main(int argc, char **argv) {
printf("MMMCalc %s, Copyright (c) 2016 Nicolás A. Ortega.\n", version);
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
printf("This program is free software and you are welcome to redistribute\n");
printf("under the terms and conditions of the GNU GPLv3 or higher.\n\n");
return 0;
}

128
src/main.c Normal file
View File

@ -0,0 +1,128 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
#include <getopt.h>
#include <unistd.h>
// Version string
const char *version = "v0.5";
// Whether or not the calculations should be verbose
bool verboseFlag = false;
// Function that prints help info
inline void printHelp();
int main(int argc, char **argv) {
// There should always be at least be 2 arguments and no more than 4
if(argc <= 1) {
fprintf(stderr, "No arguments were provided. Use `-h' for help.\n");
return 1;
}
// Variable where the argument is stored
int arg;
// If help info should be printed
bool helpFlag = false;
// If version info should be printed
bool versionFlag = false;
// The file to read the numbers from
char *infile = NULL;
while((arg = getopt(argc, argv, "hvVf:")) != -1) {
switch(arg) {
case 'h':
// Only 2 arguments can be used
if(argc != 2) {
fprintf(stderr, "Invalid use of arguments. Use `-h' for help.\n");
return 1;
}
helpFlag = true;
break;
case 'v':
verboseFlag = true;
break;
case 'V':
// Only 2 arguments can be used
if(argc != 2) {
fprintf(stderr, "Invalid use of arguments. Use `-h' for help.\n");
return 1;
}
versionFlag = true;
break;
case 'f':
// There needs to be between 3 and 4 arguments
if(argc > 4 || argc < 3) {
fprintf(stderr, "Invalid use of arguments. Use `-h' for help.\n");
}
// Set the input file
infile = optarg;
break;
case '?':
if(optopt == 'f') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else if(isprint(optopt)) {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
} else {
fprintf(stderr, "Unknown character `\\x%x'.\n", optopt);
}
return 1;
default:
// If we get anything else that's weird just abort
abort();
}
}
if(helpFlag) {
printHelp();
return 0;
} else if(versionFlag) {
printf("%s\n", version);
return 0;
}
// Print copyright & license information
printf("MMMCalc %s, Copyright (c) 2016 Nicolás A. Ortega.\n", version);
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
printf("This program is free software and you are welcome to redistribute\n");
printf("under the terms and conditions of the GNU GPLv3 or higher.\n\n");
// Open a file as read only
FILE *numfile = fopen(infile, "r");
// Temporary variable to see how many numbers are in this file
double num;
// The size of the coming nums array
int size = 0;
// Get the size for the array
while(fscanf(numfile, "%lf", &num) == 1) size++;
rewind(numfile);
printf("There are %d numbers in the file.\n", size);
// Create the array with that size
double nums[size];
for(int i = 0; i < size; i++) {
// Store result of fscanf in err
int err = fscanf(numfile, "%lf", &nums[i]);
// If fscanf returned error exit out of here
if(err != 1) {
fprintf(stderr, "Error reading entire file.\n");
return 1;
}
// If not let's continue printing
printf("%f\n", nums[i]);
}
return 0;
}
void printHelp() {
printf("Usage: mmmcalc [options]\n");
printf("Options:\n");
printf(" -f <file> -- The file to read variables from.\n");
printf(" -h -- Show this help information.\n");
printf(" -v -- Be verbose, prints the equations used.\n");
printf(" -V -- Print the version number.\n");
}