/* Write a program to print the value of EOF. */ #include <stdio.h> main() { printf("EOF is %d\n", EOF); } /* Output: EOF is -1 */…
/* Experiment to find out what happens when printf's argument string contains \c, where c is some character not listed above. */ #include <stdio.h> main() { printf("hello world\y"); printf("hello world\7"); printf("hello wor…
/* Run the "hello, world" program on your system. Experiment with leaving out parts of the program to see what error messages you get. */ #include <stdio.h> main() { printf("hello world\n"); }…
/* Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. */ #include <stdio.h> #define MAXLINE 1000 /* maximum input line size */ int getline(c…
/* Write a program to count blanks, tabs, and newlines. */ #include <stdio.h> /* count blanks, tabs, and newlines */ main() { int c, nb, nt, nl; nb = 0; /* number of blanks */ nt = 0; /* number of tabs */ nl = 0; /* number of newlines */ while((c =…
/* Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0. */ #include <stdio.h> /* print Fahrenheit-Celsius table in reverse order */ main() { int fahr; for(fahr = 300; fahr >= 0; fahr -= 20…
/* Rewrite the temperature conversion program of Section 1.2 to use a function for conversion. */ #include <stdio.h> float celsius(float fahr); /* print Fahrenheit-Celsius table or fahr = 0, 20, ..., 300; floating-point version */ main() { float fah…
/* Write a program that prints its input one word per line. */ #include <stdio.h> #define IN 1 /* inside a word */ #define OUT 0 /* outside a word */ /* print input one word per line */ main() { int c, state = OUT; while((c = getchar()) != EOF) { if…
/* Write a program to print the corresponding Celsius to Fahrenheit table. */ #include <stdio.h> /* print Celsius-Fahrenheit table for celsius = 0, 20, ..., 300; floating-point version */ main() { float fahr, celsius; int lower, upper, step; lower =…
/* Verify that the expression getchar() != EOF is 0 or 1. */ #include <stdio.h> main() { int c; while(c = getchar() != EOF) { printf("%d\n", c); } printf("%d - at EOF\n", c); }…