\documentclass{beamer}
%include lhs2TeX.fmt
\author{Piyush P Kurur\\
  Office no: 224\\
  Dept. of Comp. Sci. and Engg.\\
  IIT Kanpur}


\newcommand{\Token}[2][]{\node(#2#1)[token]{#2};}
\newcommand{\Symbol}[2][]{\node(#2#1)[symbol]{#2};}
\newcommand{\Point}[1]{\node(#1)[point]{#1};}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,chains,fit}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{matrix}
\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}
\usepackage{multicol}

\usepackage{algorithm2e}
\usepackage{pgfkeys}


%% \newcommand{\SingleLinkedList}[1]{
%%   \foreach \datum/\anchor in {#1}
%%   \begin{scope}
%%     \node[rectangle, fill=yellow!30]{#2};
%%     \node[rectangle, below, fill=green!30](#1){$\cdot$};
%%   \end{scope}
%% }
%% \newcommand{\Null}{
%%   \node[circle, fill=black, minimum size=1em]{};
%% }
\pgfkeys {%
  /tikz/redbox/.style={%
    shape=rectangle,%
    minimum size=1.5em,%
    top color = white, %
    bottom color=red!50!black!50,
    inner sep=0pt,
    draw=black
  },
  /tikz/null/.style={%
    shape=circle,
    minimum size=0.5em,
    draw=black,
  },
  /tikz/greybox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black!20,
    inner sep=0pt,
    draw=black
  },
  /tikz/blackbox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black,
    inner sep=0pt,
    draw=black
  },
  /tikz/whitebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    fill=blue!40,
    draw=black
  },
  /tikz/whitetape/.style={
    shape=rectangle,
    minimum width=4em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluearr/.style={
    ->,
    line width=0.25em, 
    draw=blue!40
  },
  /tikz/greenarr/.style={
    ->,
    line width=0.25em, 
    draw=green!40!black!60
  }
}

    
\newcommand{\arraythree}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1, right=of a0#3](a1#3){#2};
    \node[#1, right=of a1#3](a1#3){#2};
  \end{tikzpicture}
}

\newcommand{\arraytwo}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1,right=of a0#3]{#2};
  \end{tikzpicture}
}
  
\newcommand{\Array}[0]{
  \arraythree{box}{}{a}{1}
}

\newcommand{\AArray}[0]{%
  \arraythree{bbox}{\Array}{b}{0.5}}
\newcommand{\AAArray}[0]{%
  \arraytwo{bbbox}{\AArray}{c}{0.25}}


\newcommand{\T}[1]{\ensuremath{T\left(#1\right)}}  
\newcommand{\BigOh}[1]{\ensuremath{O\left(#1\right)}}
\title{Fundamentals of Computing: Lecture 30}
\date{October 19, 2009}
\begin{document}
\begin{frame}
  \maketitle
\end{frame}

\begin{frame}
  \frametitle{Summary of last class}
  \begin{itemize}
    \pause
  \item C programms can take command lines eg
    \begin{spec}
    $ progname a1 a2 .. an
    \end{spec}
    \pause
    \begin{spec}
    int main(int argc, char **argv)
    {
      /* do something */
    }
    \end{spec}
  \item The variable |argc| is one more than total arguments.
    in the above example $n+1$ and,
    \pause
  \item |argv[0]| is |progname|, |argv[1]| is |a1| etc |argv[n]| is
    |an| and |argv[n+1]| is |NULL|.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Summary continued |sprintf| and |sscanf|}
  \pause
  \begin{spec}
    int answer = 42;
    char buf[100];
    sprintf(buf, "The answer is %d", answer);
  \end{spec}
  \begin{itemize}
    \pause
  \item |sprintf| takes a character array |buf|, a format string |fmt|
    and other arguments and behaves like |printf| but prints stuff to
    the string |buf|.
    \pause
  \item |sscanf| takes a character array |buf|, a formats string |fmt|
    and other arguments and behaves like |scanf| but scans stuff from the
    string |buf|
  \end{itemize}
  \pause
  Ex Write a command like program that prints the sum of its command
  lines.
\end{frame}

\begin{frame}
\frametitle{File input output}
\begin{itemize}
  \pause
\item How does one write into a file ?
  \pause
\item How does one read from a file.
  \pause
\item What is a file ?
\end{itemize}
\end{frame}
\begin{frame}
  \frametitle{What is a file ?}
  \begin{itemize}
    \pause
  \item Files provide way to organise data on the hard disk. 
    \pause
  \item It can be hard disk of usb stick or cdrom.
    \pause
  \item In Unix everything (almost) is a file.
    \pause
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{File system and directories}
  \begin{itemize}
    \pause
  \item Files are organised into directores
    \pause
  \item Directories are trees (rose trees) and
    Files are the leaves.
    \pause
  \item The root directory is denoted by |/|.
    \pause
  \item A file or directory is completely specified by its path from the
    root eg |/foo/bar/biz| means the |biz| file under the |bar|
    directory under the |foo| directory under the root.
    \pause
  \item You can also give relative path eg |foo/bar| means the |bar|
    directory (or file) under the foo directory under the
    \emph{current} directory.
    \pause
  \item The special names |.| (dot) and |..| means this director and
    previous (or parent) directory.
  \end{itemize}
\end{frame}
\begin{frame}
  \frametitle{Using a file}
  \begin{itemize}
  \item \pause Open a file      
  \begin{spec}
    FILE *fopen(char *filename, char *mod);
  \end{spec}
  \item \pause Use it
    \begin{spec}
      int getc(FILE*);
      int fputc(int c,FILE *);
      int fprintf(FILE *fp, char *fmt, ...);
      int fscanf(FILE *fp, char *fmt, ...);
    \end{spec}
  \item \pause Close it.
    int fclose(FILE *);
  \end{itemize}
\end{frame}
\begin{frame}
\input{cat}     
\end{frame}
\end{document}
