feat: add struct-location

This commit is contained in:
dancingCycle 2023-01-03 13:32:26 +01:00
parent 70493421e9
commit c483541c29
5 changed files with 61 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
*.csv
a.out
*a.out

View File

@ -0,0 +1,28 @@
#include "location.h"
/*use assert()*/
#include <assert.h>
/*use strcmp*/
#include <string.h>
static void test_lct_lat(){
struct location lctn;
strcpy(lctn.lat, "+052.26594");
strcpy(lctn.lon, "+10.52673");
struct location lctnGet=getLocation(lctn.lat, lctn.lon);
assert(strcmp(lctn.lat, lctnGet.lat)==0 && "test_lct_lat()");
}
static void test_lct_lon(){
struct location lctn;
strcpy(lctn.lat, "+052.26594");
strcpy(lctn.lon, "+10.52673");
struct location lctnGet=getLocation(lctn.lat, lctn.lon);
assert(strcmp(lctn.lat, lctnGet.lat)==0 && "test_lct_lon()");
}
int main(){
test_lct_lat();
test_lct_lon();
}

View File

@ -0,0 +1,16 @@
#include "location.h"
struct location getLocation(char lat[11], char lon[10]){
struct location lctn;
int i,j;
for(i=0; i<11; i++){
lctn.lat[i] = lat[i];
}
for(j=0; j<10; j++){
lctn.lon[j] = lon[j];
}
return lctn;
}

View File

@ -0,0 +1,9 @@
/*use struct statement to define structure*/
struct location {
/*latitide like +052.26594*/
char lat[11];
/*longiture like +10.52673*/
char lon[10];
};
struct location getLocation(char lat[11], char lon[10]);

View File

@ -0,0 +1,7 @@
# tdd
* test location
```
gcc -Wall location-test.c location.c && ./a.out
```