gis.h file
#ifndef GIS_H
#define GIS_H
#include <stdio.h>
#include <stdint.h>
#define MAX_CHAR 256
typedef struct _Index Index;
struct _Index
{
char nameAndState[MAX_CHAR];
uint32_t offset[MAX_CHAR];
Index *pointer;
};
FILE fp1;
int CommandOrder;
char recordFileName1;
Index** hashtable;
Index* hashtableIndex;
gis.c file
#include “gis.h”
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
#include <stdint.h>
File:
char *script = argv[1];
fp1 = fopen(script,“r”); //open file
fgets(target, MAX_RECORD_CHAR, fp3);
fprintf(fp2, “%d %s %s”, k, name, state);
Memory
char db_file = malloc(MAX_CHARsizeof(char));
//malloc calloc 因为需要return,或者因为出了function之后继续保存
char * str3 = (char *) malloc(1 + strlen(name)+ strlen(state) );
//要多malloc一个位置给终止符
Value
int id = atoi(char); //change char to int
Int to String:
int num = 100;
char str[25];
sprintf(str, " %d" , num);
String:
char* word1 = strtok(eachRecord,"\t"); //string中取值
strncpy(char_pointer, eachRecord, 7); //copy string
strcpy(target, source); //copy string
strcmp(a,b) //string compare(a,b 是pointer也可以 )
if(strcmp(result->Mnemonic,“add”) == 0) // ==0意味着相同
charcount = strlen(Record); //length of a char array
char* first_token = strtok(record,"\t"); //
char* second_token = strtok(NULL,"\t"); // second 用NULL means继续token这个string
strcpy(str3, name);
strcat(str3, state);
sprintf(target, “incormation %s”, source)
scanf(source, “%s %s %d” , city, state,&pop) //后面为target
//!!***!!scanf中如果是数值,一定要加&