sandbox-c/write-location-file/main.c

46 lines
824 B
C
Raw Normal View History

2023-01-02 16:58:24 +01:00
#include<stdio.h>
/*use macro extern int errno*/
#include <errno.h>
#include <string.h>
2023-01-02 17:45:33 +01:00
#include "write-location-file.h"
2023-01-02 16:58:24 +01:00
int main()
{
FILE *fp;
/*latitude e.g. 52.26594*/
char lat [9];
/*longitude e.g. 10.52673*/
char lon [9];
printf("\nStart...\n");
fp = fopen("location.csv", "w");
if (fp==NULL)
{
/*failed to open file and associate stream*/
fprintf(stderr, "Value of errno: %d\n", errno);
fprintf(stderr, "Error opening file: %s\n", strerror(errno));
}
printf("\nEnter latitude: ");
/*read from stdin*/
scanf(" %8s", lat);
printf("\nlat: %s", lat);
printf("\nEnter longitude: ");
scanf(" %8s", lon);
printf("\nlon: %s", lon);
fprintf(fp, "%8s,%8s\n", lat, lon);
fclose(fp);
2023-01-02 18:25:51 +01:00
write_location_file("52.26594", "10.52673");
2023-01-02 17:45:33 +01:00
2023-01-02 16:58:24 +01:00
printf("\nDone!\n");
return 0;
}