feat: adjust tdd
This commit is contained in:
parent
26694a270d
commit
fff3fb8c3e
|
@ -0,0 +1,2 @@
|
|||
*.csv
|
||||
a.out
|
|
@ -38,7 +38,7 @@ int main()
|
|||
fprintf(fp, "%8s,%8s\n", lat, lon);
|
||||
fclose(fp);
|
||||
|
||||
write_location_file();
|
||||
write_location_file("52.26594", "10.52673");
|
||||
|
||||
printf("\nDone!\n");
|
||||
return 0;
|
||||
|
|
|
@ -1,16 +1,38 @@
|
|||
/*write-location-file-test.c*/
|
||||
|
||||
#include "write-location-file.h"
|
||||
|
||||
/*use printf*/
|
||||
//#include <stdio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*use macro extern int errno*/
|
||||
#include <errno.h>
|
||||
|
||||
static void test(){
|
||||
//printf("write_location_file() return %d:\n",write_location_file());
|
||||
assert(write_location_file()==0 && "test()");
|
||||
FILE* read;
|
||||
char buf[17];
|
||||
read = fopen("location-file.csv", "a+");
|
||||
|
||||
if (NULL == read) {
|
||||
/*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("content of this file are \n");
|
||||
fscanf(read, "%17s", buf);
|
||||
printf("test() buf: %17s\n", buf);
|
||||
|
||||
fclose(read);
|
||||
|
||||
char result[18] = "52.26594,10.52673";
|
||||
printf("test() result: %17s\n", result);
|
||||
|
||||
assert(strcmp(buf, result)==0 && "test()");
|
||||
//assert(write_location_file("52.26594", "10.52673")==0 && "test()");
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
|
|
@ -8,12 +8,14 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
int write_location_file(){
|
||||
int write_location_file(char *lat, char *lon){
|
||||
FILE *fp;
|
||||
|
||||
|
||||
printf("\nwrite-location-file() Start...\n");
|
||||
|
||||
printf("\nwrite-location-file() lat: %s, lon: %s\n", lat, lon);
|
||||
|
||||
fp = fopen("location-file.csv", "w");
|
||||
if (fp==NULL)
|
||||
{
|
||||
|
@ -24,7 +26,7 @@ int write_location_file(){
|
|||
|
||||
/*latitude e.g. 52.26594*/
|
||||
/*longitude e.g. 10.52673*/
|
||||
fprintf(fp, "52.26594,10.52673\n");
|
||||
fprintf(fp, "%s,%s\n", lat, lon);
|
||||
fclose(fp);
|
||||
|
||||
printf("\nwrite-location-file() Done!\n");
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/*write-location-file.h*/
|
||||
|
||||
int write_location_file();
|
||||
int write_location_file(char *lat, char *lon);
|
||||
|
|
Loading…
Reference in New Issue