implementation of push() and pop() using stack.

#define MAXVAL    100  /*maximum depth of val stack */

int sp = 0;           /*next free stack position */
double val[MAXVAL];   /*value stack */

/*push: push f onto value stack */
void push(double f){
     if (sp < MAXVAL)
         val[sp++] = f;
     else
        printf("error:stack full, cant push %g\n", f);
}

/*pop: pop and return top value from stack */
double pop(void){
      if(sp > 0)
         return val[--sp];
      else{
        printf("error: stack empty\n");
        return 0.0;
      }
}

Reverse polish calculator

#include <stdio.h>
#include <stdlib.h>   /* for atof */

#define MAXOP  100    /*max size of operand or operator */
#define NUMBER '0'    /*signal that a number was found */

int getop(char []);
void push(double);
double pop(void);

/*reverse Polish calculator */
main(){
     int type;
     double op2;
     char s[MAXOP];

     while ((type =getop(s)) != EOF){
           switch(type){
           case NUMBER:
               push(atof(s));
               break;
           case '+':
               push(pop() + pop());
               break;
          case '*':
               push(pop() * pop());
               break;
          case '-':
               op2 = pop();
               push(pop() - op2);
               break;
          case '/':
               op2 = pop();
               if (op2 != 0.0)
                  push(pop() / op2);
               else
                   printf("error: zero divisor\n");
               break;
          case '\n':
               printf("\t%.8g\n",pop());
               break;
          default:
               printf("error: unknown command %s\n", s);
               break;
           }
     }
     return 0;
}

atof:convert string to double

#include<ctype.h>

/*atof: convert string s to double */
double atof(char s[]){
      double val,power;
      int i, sign;

      for(i=0;isspace(s[i]);i++) /*skip white space */
           ;
      sign = (s[i] == '-') ? -1 : 1;
      if (s[i] == '+' || s[i] == '-')
          i++;
      for (val = 0.0; isdigit(s[i]);i++)
          val = 10.0 *val + (s[i] - '0');
      if (s[i] == '.')
          i++;
      for(power = 1.0; isdigit(s[i]);i++){
          val = 10.0 * val + (s[i] - '0');
          power *= 10.0;
      }
      return sign *val/power;
}

Find lines matching a pattern

#include <stdio.h>

#define MAXLINE  1000   /*maximum input line length */

int getline(char line[], int max);
int strindex(char source[], char searchfor[]);
char pattern[] = "ould";   /*pattern to search for */
/*find all lines matching pattern */
main()
{
    char line[MAXLINE];
    int found = 0;
     while (getline(line, MAXLINE) > 0)
         if (strindex(line, pattern) >= 0) {
            printf("%s", line);
            found++;
         }
    return found;
}

/*getline: get line into s, return length */
int getline(char s[], int lim){
     int c, i;

     i = 0;
     while(--lim > 0 && (c =getchar()) != EOF && c != '\n')
          s[i++] = c;
     if (c == '\n')
         s[i++] = c;
     s[i] = '\0';
     return i;
}

/*strindex: return index of t in s, -1 if none */
int strindex(char s[], char t[])
{
   int i, j, k;

   for(i = 0; s[i] != '\0';i++){
      for (j =i, k= 0; t[k] != '\0' && s[j] == t[k];j++, k++)
           ;
      if(k > 0 && t[k] == '\0')
         return i;
   }
  return -1;
}

shellsort.

/* shellsort: sort v[0].......v[n -1] into increasing order */
void shellsort(int v[], int n)
{
   int gap, i, j, temp;

   for(gap =n/2; gap > 0;gap /= 2)
      for(i =gap ; i < n ;i++)
         for(j =i - gap; j>= 0 && v[j] > v[j + gap]; j -=gap) {
             temp = v[j];
              v[j] =v[j + gap];
              v[j + gap] = temp;
         }
}