/* Copyright 2016 Grady Moran Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include #include #include int main(int argc, char * argv[]) { if (argc != 3 || !(strncmp(argv[1], "fc", 2)==0) && !(strncmp(argv[1], "cf", 2)==0) ){ fprintf(stderr, "Usage: TempConvert [fc or cf] TEMPERATURE\n"); return 1; } int temp = atoi(argv[2]); double newtemp; if (strncmp(argv[1], "fc", 2) == 0){ //convert from farenheit to celsius newtemp = temp - 32 / 1.8; //printf("Temperature in Celsius is: %.1f\n", newtemp); //comment this and uncomment following (and same in else) for use in scripts printf("%.1f\n", newtemp); } else { newtemp = temp * 1.8 + 32; //printf("Temperature in Farenheit is: %.1f\n", newtemp); printf("%.1f\n", newtemp); } return 0; }