Software 1 - scanf(), getline(), and unix shell (3)


Administrivia

Practice Web Page - http://www.cs.tau.ac.il/~efif/courses/Software1_Summer_03


Calculating the sign


Input format conversion


getline

#include <stdio.h>

/*! getline() reads one line from standard input and copies it to line array
 * (but no more than max chars).
 * It does not place the terminating \n in line array.
 * Returns line length, or 0 for empty line, or EOF for end-of-file.
 */
int getline(char line[], int max)
{
  int nch = 0;
  int c;
  max = max - 1;			/* leave room for '\0' */

  while ((c = getchar()) != EOF) {
    if (c == '\n')
      break;

    if (nch < max) {
      line[nch] = c;
      nch = nch + 1;
    }
  }

  if (c == EOF && nch == 0)
    return EOF;

  line[nch] = '\0';
  return nch;
}

Unix Shells


csh - Unix shell


Redirection


Variables


demo script - sort, tail


status variable


Shell prompt


Capitalizing first character


Changing the csh prompt


practices prev top next
Maintained by Efi Fogel. Last modified: August 29 2003.