feat: add struct-location
This commit is contained in:
parent
70493421e9
commit
c483541c29
|
@ -1,2 +1,2 @@
|
||||||
*.csv
|
*.csv
|
||||||
a.out
|
*a.out
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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]);
|
|
@ -0,0 +1,7 @@
|
||||||
|
# tdd
|
||||||
|
|
||||||
|
* test location
|
||||||
|
|
||||||
|
```
|
||||||
|
gcc -Wall location-test.c location.c && ./a.out
|
||||||
|
```
|
Loading…
Reference in New Issue