@alendr

Exercise # 1.9 - Character Arrays

updated September 29, 2021 · C
#include <stdio.h>
#define MAXLINE 1000 
int getline(char line[], int maxline); 
void copy(char to[], char from[]); 

/* print longest input line */ 
main()
{ 
	int len; 
	int max; 
	char line[MAXLINE]; 

Exercise 1.15 - (1.7 - Functions)

updated September 28, 2021 · C
#include <stdio.h>
float celsius(float fahr); 
/* print Fahrenheit-=Celsius table */ 
main ()
{float fahr; 
int lower, upper, step; 

lower = 0; 
upper = 300; 
step = 20; 

Example 1.8 - Arguments - Call by Value

updated September 28, 2021 · C
#include <stdio.h>
int pow(int m, int n); 
/* test power functions */ 
main() 
{
    int i; 
    for (i=0; i < 10; ++i) 
/*        printf("%d %d %d\n", i, power(2,i), power(-3,i)); */ 
          printf("%d %d %d\n", i, pow(2,i));
    return 0; 
}

1,7 - Functions

updated September 28, 2021 · C
#include <stdio.h>
int pow(int m, int n); 
/* test power functions */ 
main() 
{
    int i; 
    for (i=0; i < 10; ++i) 
/*        printf("%d %d %d\n", i, power(2,i), power(-3,i)); */ 
          printf("%d %d %d\n", i, pow(2,i));
    return 0; 
}
#include <stdio.h>

/* count digits, white space, others*/ 
main()
{
int c, i, nwhite, nother; 
int ndigit[10];

nwhite = nother = 0; 
for (i = 0; i < 10; ++i)
ndigit[i] = 0;

Exercise #1.6 - Arrays

updated September 20, 2021 · C
#include <stdio.h>
/* count digits, white spaces, others */ 
int main() {
    int c, i, nwhite, nother; 
    int ndigit[10]; 
    
    nwhite = nother = 0; 
    for (i = 0; i < 10; ++i) 
        ndigit[i] = 0; 
    
    while ((c = getchar()) != EOF) 

SDV

updated September 17, 2021 · C
#include <stdio.h>
*define MAXHIST 15
*define MAXWORD 11 
*define IN 1  
*define OUT 0 
/*print horizontal histogram */ 

int main() {
    int c, i, nc, state; 
    int len; 
    int maxvalue; 

Exercise 1-12

updated September 17, 2021 · C
#include <stdio.h>

#define IN  1 
#define OUT 0 
/*print input one word per line */ 
int main() 
{   int c, state; 
    state = OUT; 
    while ((c = getchar()) != EOF)
    { if (c == ' ' || c == '\n' || c == '\t') 
             {  if (state == IN) 

Exercise #1.5.4 -

updated September 17, 2021 · C
#include <stdio.h>
#define IN 1 
#define OUT 0 
/* Count lines, words and characters in Input */ 

int main() {
    int c, nl, nw, nc, state; 
    state = OUT; 
    nl = nw = nc = 0; 
    while ((c = getchar()) != EOF) {
        ++nc; 

Exercise #1.10 - Copy Input to Output

updated September 15, 2021 · C
#include <stdio.h>
/* replace tabs, backslashes and 
backspaces - with visible characters */ 
int main() {
    int c; 
    
    while ((c = getchar()) != EOF) { 
        if (c == '\t')
            printf("\\t"); 
        if (c == '\b')
            printf("\\b"); 

Exercise #1.10 - Copy Input to Output

updated September 15, 2021 · C
#include <stdio.h>
/* replace tabs, backslashes and 
backspaces - with visible characters */ 
int main() {
    int c; 
    
    while ((c = getchar()) != EOF) { 
        if (c == '\t')
            printf("\\t"); 
        if (c == '\b')
            printf("\\b"); 

Exercise 1.10:

September 15, 2021 · NodeJS
#include <stdio.h>
/* replace tabs, backslashes and 
backspaces - with visible characters */ 
int main() {
    int c; 
    
    while ((c = getchar()) != EOF) { 
        if (c == '\t')
            printf("\\t"); 
        if (c == '\b')
            printf("\\b"); 

Exercise 1.9:

updated September 15, 2021 · C
#include <stdio.h>
#define NONBLANK 'a' 
/* replace string of blanks with single blank */ 


int main() {
    int c, lastc; 
    lastc = NONBLANK; 
    while ((c = getchar()) != EOF) {
        if (c != ' ')
            putchar(c); 

Exercise #1.8

updated September 15, 2021 · C
#include <stdio.h>
/* Counts blanks, tabs, newlines. */ 
int main() {
    int c, nnl, nb, nt; 
    nnl = 0; /* number of newlines */   
    nb = 0; /* number of blanks */ 
    nt = 0; /* number of tabs */ 
    while ((c = getchar()) != EOF) 
        {if (c == ' ')  
            ++nb; 
         if (c == '\t') 

Exercise #1.5.3 - Line Counting

updated September 15, 2021 · C
#include <stdio.h>
/* Count lines in input */ 
int main() {
    int c, nl; 
    nl = 0; 
    while ((c = getchar()) != EOF) 
        if (c == '\n') 
            ++nl; 
    printf("%d\n", nl); 
    return 0;
}

Exercise #1.5.2 - Character Counting - 2nd Ver

updated September 15, 2021 · C
#include <stdio.h>/* Count characters as input */ 
int main() {
    double nc; 
    for (nc = 0; getchar() != EOF; ++nc)
        ; 
    
    printf("%.0f\n", nc); 
    return 0;
}

Exercise #1.5.2 - Character Counting

updated September 15, 2021 · C
#include <stdio.h>
/* Count characters in input. */ 
int main() {
    long nc; 
    while (getchar() != EOF) 
          ++nc; 
    printf("%ld\n", nc); 
    return 0;
            }

Exercise #1-7

updated September 15, 2021 · C
#include <stdio.h>
/* Prg prints EOF */
int main() {
    printf("EOF is %d\n", EOF); 
    
 
}

Exercise #1-6

updated September 15, 2021 · C
#include <stdio.h>
/* While getchar has a character - 1 is assigned to 'c'. 
    As soon as EOF is encountered - 0 is assigned &a While loop ends. */ 
int main()
{
    int c;
    while (c = getchar() != EOF)
        printf("%d\n", c); 
        
    printf("%d - at EOF\n", c); 
    

Exercise# 1.5.2 - Character Count

updated September 15, 2021 · C
#include <stdio.h>
/* count characters in input; 1st version */ 

int main() {
    long nc; 
    nc = 0; 
    while (getchar() != EOF) 
        ++nc;  
    printf("%1d\n", nc); 
}