diff --git a/dynamic.c b/dynamic.c index 997d0b1912e2df322efebd1bdd59160a42276fed..84d604af7bf2052f2e10b41cfacb36ecc2030a84 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1,7 +1,6 @@ /* Compile with: LDLIBS="-lm -ldl -lreadline" CFLAGS="-g -Wall -std=gnu11 -O3" make dynamic */ -#define _GNU_SOURCE //cause stdio.h to include asprintf #include #include #include @@ -12,12 +11,12 @@ void get_a_function(){ fprintf(f, "#include \n" "double fn(double in){\n"); char *a_line = NULL; - char *header = ">>double fn(double in){\n>> "; + char *prompt = ">>double fn(double in){\n>> "; do { free(a_line); - a_line = readline(header); + a_line = readline(prompt); fprintf(f, "%s\n", a_line); - header = ">> "; + prompt = ">> "; } while (strcmp(a_line, "}")); fclose(f); } diff --git a/gsl_distance.c b/gsl_distance.c index 4e994aca4afad76c14e6dba781ae9061ecb4657c..721568f98deb3817d8220f668cee4f42098956b9 100644 --- a/gsl_distance.c +++ b/gsl_distance.c @@ -12,7 +12,7 @@ double one_dist(gsl_vector *v1, void *v2){ long double distance(apop_data *data, apop_model *model){ gsl_vector *target = model->parameters->vector; - return -apop_map_sum(data, .fn_vp=one_dist, .param=target, .part='r'); + return -apop_map_sum(data, .fn_vp=one_dist, .param=target); } apop_model *min_distance= &(apop_model){ @@ -25,9 +25,8 @@ int main(){ 2.9, 8.6, -1.3, 3.7, 2.9, 1.1); - Apop_model_add_group(min_distance, apop_mle, .method= APOP_SIMPLEX_NM, + Apop_model_add_group(min_distance, apop_mle, .method= "NM simplex", .tolerance=1e-5); - Apop_model_add_group(min_distance, apop_parts_wanted); - apop_model *est=apop_estimate(locations, min_distance); + apop_model *est = apop_estimate(locations, min_distance); apop_model_show(est); } diff --git a/seamlessthree.c b/seamlessthree.c new file mode 100644 index 0000000000000000000000000000000000000000..03d6b8b7e3cedcc8af085e506bdac57a96b0cc74 --- /dev/null +++ b/seamlessthree.c @@ -0,0 +1,34 @@ +/* Compile with: +make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11" seamlessthree +*/ +#include +#include + +typedef struct point { + double x, y; +} point; + +typedef struct { + union { + struct { + double x, y; + }; + point p2; + }; + double z; +} threepoint; + +double length (point p){ + return sqrt(p.x*p.x + p.y*p.y); +} + +double threelength (threepoint p){ + return sqrt(p.x*p.x + p.y*p.y + p.z*p.z); +} + +int main(){ + threepoint p = {.x=3, .y=0, .z=4}; + printf("p is %g units from the origin\n", threelength(p)); + double xylength = length(p.p2); + printf("Its projection onto the XY plane is %g units from the origin\n", xylength); +} diff --git a/seamlesstwo.c b/seamlesstwo.c index 54849753db3ceeff61998f5f0595e75085d90421..8b48d3310fa8fe8cb72dfc427feab5dcc1ed14c7 100644 --- a/seamlesstwo.c +++ b/seamlesstwo.c @@ -1,5 +1,5 @@ /* Compile with: -make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11 --ms-extensions" seamlesstwo +make LDLIBS='-lm' CFLAGS="-g -Wall -std=gnu11 -fms-extensions" seamlesstwo */ #include #include diff --git a/times_table.c b/times_table.c index d50d6f915edee1510166899ec9769f93721005a5..ae5fba427d8f39f372d0b3b08bfc8afb710bd797 100644 --- a/times_table.c +++ b/times_table.c @@ -9,7 +9,6 @@ void matrix_cross_base(double *list1, double *list2){ int count1 = 0, count2 = 0; while (!isnan(list1[count1])) count1++; while (!isnan(list2[count2])) count2++; - if (!count1 || !count2) {printf("missing data."); return;} for (int i=0; i int main(){ - printf("3./5=%g\n", 3./5); - printf("3/5=%i\n", 3/5); - printf("3%%5=%i\n", 3%5); + printf("13./5=%g\n", 13./5); + printf("13/5=%i\n", 13/5); + printf("13%%5=%i\n", 13%5); } diff --git a/tutorial/do_while.c b/tutorial/do_while.c index c178f937910f23e81cfdcfc6d6273ff3dd22b663..4edeeda6d1a1a2ba001a8bf10bf0eac178733690 100644 --- a/tutorial/do_while.c +++ b/tutorial/do_while.c @@ -6,7 +6,6 @@ void loops(int max){ printf("Hello #%i\n", i); i++; } while (i < max); //Note the semicolon. - } int main(){ diff --git a/tutorial/item_seven.c b/tutorial/item_seven.c index 8bca9be007dbfa13d04da79aed1f285cbdd92fb2..061b65c2d97020b45f2396756387efb22cfe508f 100644 --- a/tutorial/item_seven.c +++ b/tutorial/item_seven.c @@ -7,6 +7,6 @@ int main(){ char string[len]; intlist[7] = 7; - snprintf(string, 20, "Item seven is %i.", intlist[7]); + snprintf(string, len, "Item seven is %i.", intlist[7]); printf("string says: <<%s>>\n", string); } diff --git a/tutorial/pointer_in.c b/tutorial/pointer_in.c index dcf9630b0c2a44d4e6db1fc7fa4047b3508bba1f..cf8c8fc12d5db067a0c9fc712797fdaa617b5520 100644 --- a/tutorial/pointer_in.c +++ b/tutorial/pointer_in.c @@ -6,7 +6,7 @@ void double_in(int *in){ } int main(){ - int *x= malloc(sizeof(int)); + int x[1]; *x= 10; double_in(x); printf("x now points to %i.\n", *x); diff --git a/unicode.c b/unicode.c index f47a5c2599b5d5e736738b87f1c9ed93f3d57df0..f675787fea61306c8e13d5f9c190d4172dc839f0 100644 --- a/unicode.c +++ b/unicode.c @@ -40,6 +40,7 @@ int main(int argc, char **argv){ char *ucs = localstring_to_utf8(string_from_file(argv[1])); Stopif(!ucs, return 1, "Exiting."); + FILE *out = fopen("uout.html", "w"); Stopif(!out, return 1, "Couldn't open uout.html for writing."); fprintf(out, "", strlen(ucs)); fprintf(out, "Here it is, with each space-delimited element on a line " "(with commentary on the first character):
"); + ok_array *spaced = ok_array_new(ucs, " \n"); for (int i=0; i< spaced->length; i++, (spaced->elements)++){ fprintf(out, "%s", *spaced->elements);