-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_data.c
32 lines (31 loc) · 842 Bytes
/
create_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
/* This is a sample code that creates a datafile named `data.txt`.
We use this later on for the analysis.
This code is a simple demonstration of file write using C.
Usage:
Enter the x and y values for the observation datapoint sperated by space.
Each observation must end with a newline.
To finish taking data and ending the program enter `-1 -1`.
*/
int main() {
FILE *fp = fopen("data.txt", "w");
if (fp == NULL) {
printf("Error opening file\n");
return 1;
}
printf("Enter data x y\n");
float x, y;
while (1) {
scanf("%f %f", &x, &y);
if (x == -1 && y == -1) {
break;
}
fprintf(fp, "%f %f\n", x, y);
}
fclose(fp);
return 0;
}