Skip to content

Commit

Permalink
write to file, const char separator
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfrantz committed Jan 31, 2024
1 parent 8fee771 commit d555e0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/cross-level/table-cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ int width, *max_width = NULL;
--- separator: column separator
+++ Return: void
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
void write_table(table_t *table, char *fname, char *separator){
void write_table(table_t *table, char *fname, const char *separator){
int row, col;
FILE *fp = NULL;

Expand All @@ -360,18 +360,18 @@ FILE *fp = NULL;

if (table->has_col_names){

if (table->has_row_names) printf("rowname%s", separator);
if (table->has_row_names) fprintf(fp, "rowname%s", separator);

for (col=0; col<(table->ncol-1); col++) printf("%s%s", table->col_names[col], separator);
printf("%s\n", table->col_names[col]);
for (col=0; col<(table->ncol-1); col++) fprintf(fp, "%s%s", table->col_names[col], separator);
fprintf(fp, "%s\n", table->col_names[col]);

}

for (row=0; row<table->nrow; row++){

if (table->has_row_names) printf("%s%s", table->row_names[row], separator);
for (col=0; col<(table->ncol-1); col++) printf("%.2f%s", table->data[row][col], separator);
printf("%.2f\n", table->data[row][col]);
if (table->has_row_names) fprintf(fp, "%s%s", table->row_names[row], separator);
for (col=0; col<(table->ncol-1); col++) fprintf(fp, "%.2f%s", table->data[row][col], separator);
fprintf(fp, "%.2f\n", table->data[row][col]);

}

Expand Down
2 changes: 1 addition & 1 deletion src/cross-level/table-cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ table_t read_table(char *fname, bool has_row_names, bool has_col_names);
table_t allocate_table(int nrow, int ncol, bool has_row_names, bool has_col_names);
void init_table(table_t *table);
void print_table(table_t *table, bool truncate);
void write_table(table_t *table, char *fname, char *separator);
void write_table(table_t *table, char *fname, const char *separator);
void free_table(table_t *table);

#ifdef __cplusplus
Expand Down

0 comments on commit d555e0c

Please sign in to comment.