/** * main * 標準入出力を行う関数 * @input * コマンドラインからの時刻文字列 * @output * 調べた結果の標準出力 */ int main(int argc, char *argv[]){ //時刻の数値を格納するメモリ領域の確保 int times[3]; //コマンドライン引数の個数チェック if(argc != ARGMENTS_LIMIT){ printf("Error! Please input 3 arguments as the time, start time and end time.\n"); exit(1); } //時刻の数値を取り出す args2Int(argv, ×[0]); //エラーチェック checkInputError(times); //調べた結果の標準出力 //範囲内の場合 if(searchTimeRange(times) == 1){ //任意の処理を書く printf("%d時は%d時から%d時に含まれます\n", times[0], times[1], times[2]); } //範囲外の場合 else{ //任意の処理を書く printf("%d時は%d時から%d時に含まれません\n", times[0], times[1], times[2]); } }
int main(int argc, const char * argv[]) { if(argc < 5 || argc > 5) { printf("Usage: ./bikehelper start_long start_lat end_long end_lat (in degrees) \n"); exit(1); } int h; for( h = 1; h < argc; h++) { checkInputError(h, argv); } if(-180 > atof(argv[1]) || atof(argv[1]) > 180.0) { printf("Longtitude between -180 and 180 only \n"); exit(1); } if(-180 > atof(argv[3]) || atof(argv[3]) > 180.0) { printf("Longtitude between -180 and 180 only \n"); exit(1); } if(-90 > atof(argv[2]) || atof(argv[2]) > 90 ) { printf("Latitude between -90 and 90 only \n"); exit(1); } if(-90 > atof(argv[4]) || atof(argv[4]) > 90) { printf("Latitude between -90 and 90 only \n"); exit(1); } char *first_bikestop; char *destination_file; int file_size = (int)loadToMemory("/usr/local/unnc/ae1prg/npb/stops.txt" , &destination_file); char *second_bikestop; double longtitude_bus[3]; double latitude_bus[3]; char busStop_name[3][40]; char *direction[3]; int bearing[3]; printf("Starting from %s %s \n", argv[1], argv[2]); /* ---------------------------------- First part of the output ----------------------------------- */ char *stop = toBikeStop(destination_file, atof(argv[1]), atof(argv[2]), file_size, &first_bikestop); sscanf(first_bikestop, "%lf %lf %s", &longtitude_bus[0], &latitude_bus[0], busStop_name[0]); bearing[0] = getBearing(atof(argv[1]), atof(argv[2]), longtitude_bus[0], latitude_bus[0]); getDirection(bearing[0], &direction[0]); printf("Walk %s to %s at %f, %f \n", direction[0], busStop_name[0], longtitude_bus[0], latitude_bus[0]); /* ---------------------------------- Second part of the output ----------------------------------- */ char * stop1 = toBikeStop(destination_file, atof(argv[3]), atof(argv[4]), file_size, &second_bikestop); sscanf(second_bikestop, "%lf %lf %s", &longtitude_bus[1], &latitude_bus[1], busStop_name[1]); bearing[1] = getBearing(longtitude_bus[0], latitude_bus[0], longtitude_bus[1], latitude_bus[1]); getDirection(bearing[1], &direction[1]); printf("Cycle %s to %s at %f, %f \n", direction[1], busStop_name[1], longtitude_bus[1],latitude_bus[1]); /* ---------------------------------- Third part of the output ----------------------------------- */ bearing[2] = getBearing(longtitude_bus[1], latitude_bus[1], atof(argv[3]), atof(argv[4])), getDirection(bearing[2], &direction[2]); printf("Walk %s to your destination at %f, %f \n",direction[2],atof(argv[3]), atof(argv[4])); free(stop); free(stop1); free(destination_file); return 0; }