Arguments to main() int main(int argc, char *argv[]) { int i; printf("argc = %d\n",argc); for (i=0; i<argc; i++) printf("argv[%d] = %s\n",i,argv[i]); return 0; }
Arguments to main() fox01> ./myprog this is apple argc = 4 argv[0] = ./myprog argv[1] = this argv[2] = is argv[3] = apple
Fahrenheit to Celcius #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { double fahrenheit, celcius; fahrenheit = atof(argv[1]); celcius = (fahrenheit-32)*5.0/9; printf("Celcius = %f\n",celcius); }
Arguments to main() fox01> ./fahtocelcius 36 Celcius = 2.222222
Fahrenheit to Celcius #include <stdio.h> #include <stdlib.h> int main() { double fahrenheit, celcius; printf("Enter fahrenheit"); scanf("%lf",&fahrenheit); celcius = (fahrenheit-32)*5.0/9; printf("Celcius = %f\n",celcius); }
Arguments to main() fox01> ./fahtocelcius2 < f.txt Enter fahrenheitCelcius = 1.111111 f.txt file has the following 34