Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file q11210332221.c
- * @brief サンプルプログラム
- * @author Keitetsu
- * @date 2019/07/12
- * @copyright Copyright (c) 2019 Keitetsu
- * @par License
- * This software is released under the MIT License.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define N_DATA (720) /**< Number of data */
- size_t set_wave_data(void *array, size_t array_size);
- int main(int argc, char *argv[])
- {
- double *array;
- size_t array_size;
- size_t ret_val;
- FILE *fp;
- size_t t;
- array_size = sizeof(double) * N_DATA;
- array = (double *)malloc(array_size);
- if (array == NULL) {
- fprintf(stderr, "[ERROR] Failed to allocate memory.\n");
- return 1;
- }
- ret_val = set_wave_data(array, array_size);
- fp = fopen("wave_data.csv", "w");
- if (fp == NULL) {
- fprintf(stderr, "[ERROR] Failed to open the file.\n");
- free(array);
- return 2;
- }
- for (t = 0; t < ret_val; t++) {
- fprintf(fp, "%zu, %lf\n", t, array[t]);
- }
- fclose(fp);
- free(array);
- return 0;
- }
- size_t set_wave_data(void *array, size_t array_size)
- {
- size_t n_data;
- size_t t;
- n_data = array_size / sizeof(double);
- for (t = 0; t < n_data; t++) {
- ((double *)array)[t] = sin(t * M_PI / 180.0);
- }
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement