Compare commits

9 Commits

Author SHA1 Message Date
fd31a58e26 Changed version string. 2014-11-04 11:42:51 -06:00
072029db8a Using obj/ for .o files. 2014-11-04 11:41:35 -06:00
53d372675d Simplifying if statements. 2014-11-04 11:32:55 -06:00
231437872a Misplaced double-quote. 2014-11-03 19:49:14 -06:00
0e63f6af23 Added to a comment. 2014-11-03 11:50:05 -06:00
165213a1ad Added comments. 2014-11-03 11:47:49 -06:00
f116a4727c Fixed failsafe. 2014-11-03 10:07:27 -06:00
23e0889167 Will create deb outside project. 2014-10-30 18:14:00 -05:00
ed5f340e68 Ignore deb creating directory. 2014-10-30 18:10:59 -05:00
3 changed files with 38 additions and 11 deletions

View File

@ -9,17 +9,17 @@ MKDIR=mkdir -p
RM=rm -rf RM=rm -rf
SRC_FILES := $(wildcard src/*.c) SRC_FILES := $(wildcard src/*.c)
OBJ_FILES := $(addprefix src/, $(notdir $(SRC_FILES:.c=.o))) OBJ_FILES := $(addprefix obj/, $(notdir $(SRC_FILES:.c=.o)))
all: $(OBJ_FILES) all: $(OBJ_FILES)
$(MKDIR) bin $(MKDIR) bin
$(CXX) $(CXXFLAGS) $(LIBS) -o bin/cointoss src/*.o $(CXX) $(CXXFLAGS) $(LIBS) -o bin/cointoss obj/*.o
src/%.o: src/%.c obj/%.o: src/%.c
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $< $(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
clean: clean:
$(RM) src/*.o $(RM) obj/*.o
cleanall: clean cleanall: clean
$(RM) bin $(RM) bin

1
obj/readme.txt Normal file
View File

@ -0,0 +1 @@
This is where the object output files go. This readme file is a simple hack so that git registers it (git doesn't register empty directories).

View File

@ -16,28 +16,51 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
char version[7] = "v0.1"; // Global version string
char version[7] = "v0.2";
/* Function prototypes start */
void printCopyright(); void printCopyright();
void printAllCopyright(); void printAllCopyright();
void printWarranty(); void printWarranty();
/* Function prototypes end */
// Main function:
int main(int argc, char **argv) { int main(int argc, char **argv) {
if(argc < 2 || argc > 3) { // If inappropriate number of arguments
printf("Usage: %s [trials]\n", argv[0]); if(argc < 2 || argc > 3) { // If inappropriate number of arguments (number required = 2)
printf("Inappropriate amount of arguments.");
printf("Usage: %s [num_trials]\n", argv[0]);
return 1; return 1;
} }
if(strcmp(argv[1], "-c") == 0) { if(!strcmp(argv[1], "-c")) { // If argv[1] (the second argument) is equal to "-c" ...
printAllCopyright(); printAllCopyright();
return 0; return 0;
} else if(strcmp(argv[1], "-w") == 0) { } else if(!strcmp(argv[1], "-w")) { // If argv[1] is equal to "-w"
printWarranty(); printWarranty();
return 0; return 0;
} else if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { // If argv[1] is equal to "-h" or "--help"
printf("Usage: %s [num_trials]\n\
-c -- Print copyright info\n\
-h | --help -- Print this help information\n\
-w -- Print warranty information\n", argv[0]);
return 0;
} else {
int i = 0;
while(argv[1][i] != '\0') { // While argv[1][i] is not equal to NULL (can't use NULL for pointers)
if(isdigit(argv[1][i] - '0') != 0) { // if argv[1][i] is not a number between 0 and 9
printf("You did not specify a number.\n");
printf("Usage: %s [num_trials]\n", argv[0]);
return 1;
}
i++;
}
} }
printCopyright(); printCopyright();
@ -46,12 +69,13 @@ int main(int argc, char **argv) {
int heads = 0; int heads = 0;
int tails = 0; int tails = 0;
// Setup the random number generator with the seed being the time
srand(time(NULL)); srand(time(NULL));
printf("Working...\n"); printf("Calculating random numbers...\n");
for(int i = 0; i < trials; i++) { for(int i = 0; i < trials; i++) {
if(i % 100000000 == 0) printf("Working...\n"); if(i % 100000000 == 0) printf("Working...\n");
int r = rand() % 100 + 1; int r = rand() % 100 + 1; // Calculate random number between 1 and 100
if(r <= 50) heads++; if(r <= 50) heads++;
else tails++; else tails++;
} }
@ -62,6 +86,7 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
/* Defined functions start */
void printCopyright() { void printCopyright() {
printf("CoinToss %s Copyright (C) 2014 Nicolás A. Ortega\n\ printf("CoinToss %s Copyright (C) 2014 Nicolás A. Ortega\n\
This program comes with ABSOLUTELY NO WARRANTY; for details use `-w'.\n\ This program comes with ABSOLUTELY NO WARRANTY; for details use `-w'.\n\
@ -94,3 +119,4 @@ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\n\
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\n\ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\n\
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n"); ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n");
} }
/* Defined functions end */