Script started on Thu Jan 23 09:12:59 2003
 [root@Fizzgig /root]# cd C
 [root@Fizzgig C]# cat lowercase.c
/* lowercase.c                                                   */
/* Changes all uppercase characters given through standard input */
/*  to lowercase                                                 */
/*                                                               */
/* Author: Zach Tomaszewki                                       */
/* Date: 22 Jan 2003                                             */

#include <stdio.h>

int main (){

  char nextChar = getchar();
  while (nextChar != EOF){
    if (nextChar > 64 && nextChar < 91){ //is an uppercase ASCII char
      nextChar += 32;
    }
    printf("%c", nextChar);
    nextChar = getchar(); 
  }
  return 0;
}
[root@Fizzgig C]# gcc -g lowercase.c -o lowercase
[root@Fizzgig C]# lowercs ase < se.txt
secret de deux, secret de dieu, secret de trois, secret de tous. (french proverb)[root@Fizzgig C]# cat uppercase.c
/* uppercase.c                                                   */
/* Changes all lowercase characters given through standard input */
/*   to uppercase                                                */
/*                                                               */
/* Author: Zach Tomaszewki                                       */
/* Date: 23 Jan 2003                                             */

#include <stdio.h>

int main (){

  char nextChar = getchar();
  while (nextChar != EOF){
    if (nextChar >= 97 && nextChar <= 122){ // is lowercase ASCII char
      nextChar -= 32;
    }
    printf("%c", nextChar);
    nextChar = getchar(); 
  }
  return 0;
}
]0;root@Fizzgig.localdomain: /root/C[root@Fizzgig C]# gcc -g uppercase.c up  -o upt percase
[root@Fizzgig C]# uppercase < se.txt
SECRET DE DEUX, SECRET DE DIEU, SECRET DE TROIS, SECRET DE TOUS. (FRENCH PROVERB)[root@Fizzgig C]# cat replacetabs.c
/* replacetabs.c                                              */
/* Replace all tabs in a file, given through standard input,  */
/*  with a give number of spaces.                             */
/*  Default is 4 spaces.  Tabs must be replaces by >0 spaces. */
/* Example: "replacetabs 3 < my.txt"                          */
/*                                                            */
/* Author: Zach Tomaszewski                                   */
/* Date: 23 Jan 2003                                          */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(int argc, char *argv[]){
  int tabstop = 4;
  int nextChar = 0;
  int charCount =0;

  /* Check that input is in correct format */
  if (argc == 2 && isdigit(*argv[1]) && atoi(argv[1]) > 0){
    tabstop = atoi(argv[1]);
  }else if (argc == 1) {
    //use default tabstop value
  }else{
    printf("Usage: replacetabs [tabstop]\n");
    printf("\t Replaces all tabs with spaces until the next tabstop.\n");
    printf("\t [tabstop] must be greater than 0. Default = 4.\n");
    printf("Examples:\n");
    printf("\t replacetabs < my.txt\n");
    printf("\t replacetabs 5 <in.txt >out.txt \n");
    exit(1);
  }

  /* Work through input, keeping track of current column */
  nextChar = getchar();
  while(nextChar != EOF) {
    if (nextChar == *"\n") { //compare to int value of "\n"
      charCount = 0; //reset line count
      putchar(nextChar);
    }else if (nextChar == *"\t"){
      do{
        putchar(*" "); //replace with a space
        charCount++;
      }while(charCount % tabstop != 0); //add spaces till next tabstop
    }else{
      putchar(nextChar);
      charCount++;
    }
    nextChar = getchar();
  }

}

[root@Fizzgig C]# cat makefile
replacetabs: replacetabs.o
	gcc -g replacetabs.o -o replacetabs

replacetabs.o: replacetabs.c
	gcc -g -c replacetabs.c
[root@Fizzgig C]# make
gcc -g -c replacetabs.c
gcc -g replacetabs.o -o replacetabs
[root@Fizzgig C]# replacetabs < isort.ct
/* An example of sorting a list of strings by  */

/* rearranging the pointers and not moving the */

/* strings themselves.       WP--9/99          */



#include <stdio.h>

#include <string.h>



/* swap the pointers that s and t point to  */

void swap(char **s, char **t)

{

    char* u;

    u = *s;

    *s = *t;

    *t = u;

}



/* Sort the n elements of v[] using an insertion sort */

/* v is assumed to be an array of pointers to strings */

/* This rearranges the pointers in array v.           */

void isort(char **v, int n)

{

    int i, j;



    for(i = 1; i<n; i++) {

    ....for(j = i; j>0; j--) {

            if(strcmp(v[j],v[j-1])<0) swap(v+j, v+j-1);

        }

    }

}

/* Short main program to test isort()   */

void main()

{

    int i;

    char *a[] = {"oranges", "grapes", "peaches",

        "apples", "pears", "mangos", "lychees"};

    printf("Unsorted:\n");

    for(i = 0; i<7; i++) printf("%s\n",a[i]);

    isort(a, 7);

    printf("\nSorted:\n");

    for(i = 0; i<7; i++) printf("%s\n",a[i]);

}

[root@Fizzgig C]# replacetabs 6 < prime.txt
Table of Prime Numbers

0     3     5     7     11    13    17    19    23    29

31    37    41    43    47    53    59    61    67    71

73    79    83    89    97    101   103   107   109   113

127   131   137   139   149   151   157   163   167   173

179   181   191   193   197   199   211   223   227   229

233   239   241   251   257   263   269   271   277   281

283   293   307   311   313   317   331   337   347   349

353   359   367   373   379   383   389   397   401   409

419   421   431   433   439   443   449   457   461   463

467   479   487   491   499   503   509   521   523   541

[root@Fizzgig C]# exit

Script done on Thu Jan 23 09:23:35 2003
