<repo_name>york18/2031-C-and-shell-scripting<file_sep>/A2/Q2 (1)/allfiles
#!/bin/sh
# EECS2031 - asg2
# Filename: allfiles
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

for f in *
do
	if test -f $f
	then
		echo $f
	fi
done
<file_sep>/A2/Q2 (1)/myutil
#!/bin/sh
# EECS2031 - asg2
# Filename: myutil
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

menu
echo
echo -n "Enter command: "

while read command 
do
	case $command in
	s | S)	isearch;;
	c | C) 	icount;;
	f | F) 	allfiles;;
	v | V)	fdisplay;;
	d | D)	doublesp;;
	a | A)	addlines;;
	l | L)	prtlines;;
	h | H)	menu;;	
	r | R)	clear;;
	q | Q)	exit 1;;
	*)		echo "Invalid command";;
	esac
	echo
	echo -n "Enter command: "
done<file_sep>/A2/Q1 (1)/try1.c
#include <stdio.h>
#include <stdlib.h>


/***************** DO NOT USE ARRAY INDEXING *****************/
/************** USE ONLY POINTERS IN THIS FILE ***************/

int toString(char []);

int main()
{
  char a[100];
  int n;

  printf("Input a valid string to convert to integer\n");
  scanf("%s", a);

  n = toString(a);

  printf("String  = %s\nInteger = %d\n", a, n);

  return 0;
}

int toString(char a[]) {
  int c, sign, offset, n;

  if (a[0] == '-') {  // Handle negative integers
    sign = -1;
  }

  if (sign == -1) {  // Set starting position to convert
    offset = 1;
  }
  else {
    offset = 0;
  }

  n = 0;

  for (c = offset; a[c] != '\0'; c++) {
    n = n * 10 + a[c] - '0';
  }

  if (sign == -1) {
    n = -n;
  }

  return n;
}


/*
   Save the three command-line arguments into nr1, nc1 and nc2.
 */

void get_args( char **argv, int *nr1, int *nc1, int *nc2 )
{

   /*************** ADD YOUR CODE HERE ***************/

}




/*
   Initialize a 2-dimensional array.
   Element (i, j) is assigned value i+j.
 */

void initMatrix ( int **a, int nrows, int ncols )
{

   /*************** ADD YOUR CODE HERE ***************/

}





/*
   Multiply arrays a and b.
   Array a has nr1 rows and nc1 columns.
   Array b has nc1 rows and nc2 columns.
   Allocate an array c having nr1 rows and nc2 columns.
   Compute a x b and store the result in array c.
   Return array c.
   If an error occurs (e.g., insufficient memory), return NULL pointer.
 */


int **matrix_mult( int **a, int **b, int nr1, int nc1, int nc2 )
{

   /*************** ADD YOUR CODE HERE ***************/

   return( NULL );	/* replace this line with your code */
}



/************************* END OF FILE *************************/
<file_sep>/A2/Q2 (1)/icount
#!/bin/sh
# EECS2031 - asg2
# Filename: icount
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

echo -n "Enter the file name: "
read filename

if test ! -f $filename
then
echo "File '$filename' does not exist."

elif test ! -r $filename
then echo "File '$filename' is not readable."

else

echo -n "Count lines, words, characters or all three (l, m, c, a)? "
read varname

until test $varname = l || test $varname = L || test $varname = m || test $varname = M || test $varname = c || test $varname = C || test $varname = a || test $varname = A
do
echo "Invalid option"
echo -n "Count lines, words, characters or all three (l, w, c, a)? "
read varname
done

if test $varname = l || test $varname = L
then
	lines=`wc -l < $filename` 
	echo "File '$filename' contains $lines lines."

elif test $varname = m || test $varname = M 
then
	words=`wc -w < $filename` 
	echo "File '$filename' contains $words words." 

elif test $varname = c || test $varname = C
then
	characters=`wc -m < $filename`
	echo "File '$filename' contains $characters characters." 

elif test $varname = a || test $varname = A
then
	lines=`wc -l < $filename`
	words=`wc -w < $filename`
	characters=`wc -m < $filename`
	echo "File '$filename' contains $lines lines, $words words, $characters characters." 

else
	echo "Invalid option" 
fi

fi<file_sep>/Labs/Lab4/lab4a.c
/***********************************
* EECS2031 - Lab 4
* Filename: lab4a.c
* Author: Last name, first name
* Email: Your preferred email address
* Login ID: Your login ID
************************************/

#include <stdio.h>

#define MAX_SIZE 500

void myStrInput ( char *s );
int myStrCmp( char *s1, char *s2 );

int main()
{
    char strg1[ MAX_SIZE ], strg2[ MAX_SIZE ];

    myStrInput( strg1 );
    myStrInput( strg2 );
    printf( "%d\n", myStrCmp( strg1, strg2 ));
    return 0;
}

void myStrInput ( char *s )
{

    int c = getchar();
    int i = 0;
    while(c != '\n')
    {
        *(s + i) = c;
        i++;
        c = getchar();
    }
    *(s + i) = '\0';
}

int myStrCmp( char *s1, char *s2 )
{

    int i = 0;
    for(; *(s1 + i) != '\0'; i++)
    {
        if(*(s1 + i) != *(s2 + i))
        {
            return i;
        }
        else
        {
            if(*(s1 + i + 1) == '\0' && *(s2 + i + 1) == '\0')
            {
                return -1;
            }
        }
    }
    return i;

}

<file_sep>/Labs/lab8/q2/mkpub
#!/bin/sh
if test -d $1
then
	chmod a+rx $1
	echo "Directory '$1' is now made public."
elif test -f $1
then
	echo "File '$1' is now made public."
	chmod a+r $1
else
	echo "File '$1' does not exits."
fi
<file_sep>/A2/Q1 (1)/mm.c
/***********************************
* EECS 2031 - Assignment 2
* Filename: mm.c
* Author: <NAME>
* Email: <EMAIL>
* Login ID: york18
************************************/


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


/***************** DO NOT USE ARRAY INDEXING *****************/
/************** USE ONLY POINTERS IN THIS FILE ***************/

static int** allocate2D( int nrows, int ncols )
{

    int **array, i;

    /* Allocate an array of pointers, each pointing to a row. */
    array = ( int** ) malloc( nrows * sizeof( int* ) );
    if ( array == NULL )
    {
        printf( "Insufficient memory!\n" );
        exit ( 1 );
    }

    /* Allocate each row. */
    for(i = 0; i < nrows; i++)
    {
        *(array + i) = ( int* ) malloc( ncols * sizeof( int ) );
        if ( *(array + i) == NULL )
        {
            printf( "Insufficient memory!\n" );
            exit ( 1 );
        }
    }

    return( array );

}


/*
* Converts a char array into an int
*/
int toInt(char *a)
{
    int c, sign, offset, n;
    offset = 0;
    if (*(a + 0) == '-')    // Handle negative integers
    {
        sign = -1;
    }

    if (sign == -1)    // Set starting position to convert
    {
        offset = 1;
    }
    else
    {
        offset = 0;
    }

    n = 0;

    for (c = offset; *(a+c) != '\0'; c++)
    {
        n = n * 10 + *(a+c) - '0';
    }

    if (sign == -1)
    {
        n = -n;
    }
    return n;
}



/*
   Save the three command-line arguments into nr1, nc1 and nc2.
 */

void get_args( char **argv, int *nr1, int *nc1, int *nc2 )
{
    *nr1 = toInt(*(argv + 1));
    *nc1 = toInt(*(argv + 2));
    *nc2 = toInt(*(argv + 3));
}




/*
   Initialize a 2-dimensional array.
   Element (i, j) is assigned value i+j.
 */

void initMatrix ( int **a, int nrows, int ncols )
{
    int i = 0;
    for(; i < nrows; i++)
    {
        int j = 0;
        for(; j < ncols; j++)
        {
            *(*(a + i) + j) = i + j;
        }

    }

}





/*
   Multiply arrays a and b.
   Array a has nr1 rows and nc1 columns.
   Array b has nc1 rows and nc2 columns.
   Allocate an array c having nr1 rows and nc2 columns.
   Compute a x b and store the result in array c.
   Return array c.
   If an error occurs (e.g., insufficient memory), return NULL pointer.
 */


int **matrix_mult( int **a, int **b, int nr1, int nc1, int nc2 )
{
    int **mm;
    mm = allocate2D(nr1, nc2);
    int sum = 0;
    int i = 0;
    int j = 0;
    int k = 0;
    for (i = 0; i < nr1; i++)
    {
        for (j = 0; j < nc2; j++)
        {
            for (k = 0; k < nc1; k++)
            {
                sum = sum + (*(*(a + i)+ k) * (*(*(b + k) + j)));
            }
            *(*(mm + i) + j) = sum;
            sum = 0;
        }
    }
    return( mm );
}



/************************* END OF FILE *************************/

<file_sep>/A1/Q1- Polynomial/poly.c
/***********************************
* EECS2031 - Assignment 1
* Filename: poly.c
* Author: <NAME>
* Email: <EMAIL>
* Login ID: york18
************************************/

#include "poly.h"
void toCharArray(int n1, char *s);
void sort( int coeff[ ], int exp[ ] );

int len = 0;
/*
  Initialize all coefficients and exponents of the polynomial to zero.
 */
void init_polynom( int coeff[ ], int exp[ ] )
{
    int i = 0;
    for (; i < ASIZE; i++)
    {
        coeff[i] = exp[i]= 0;
    }
}  /* end init_polynom */


/*
  Get inputs from user using scanf() and store them in the polynomial.
 */
void get_polynom( int coeff[ ], int exp[ ] )
{
    int l = 0;
    int total;
    scanf("%d", &total);
    while(total > 0)
    {
        scanf("%d", &coeff[l]);
        scanf("%d", &exp[l]);
        total--;
        l++;
    }
    coeff[l] = '\0';
    exp[l] = '\0';

}  /* end get_polynom */

void sort( int coeff[ ], int exp[ ] )
{
    int i = 0;
    int j = 0;
    int a;
    int b;

    for(; coeff[i] != '\0' || exp[i] != '\0'; i++)
    {
        j = 0;
        for (j = i + 1; coeff[j] != '\0' || exp[j] != '\0'; j++)
        {
            if (exp[i] < exp[j])
            {
                a = exp[i];
                b = coeff[i];
                exp[i] = exp[j];
                coeff[i] = coeff[j];
                exp[j] = a;
                coeff[j] = b;
            }
        }
    }
}

/*
  Convert the polynomial to a string s.
 */
void polynom_to_string( int coeff[ ], int exp[ ], char s[ ] )
{
    int j = 0;
    int k = 0;
    int l = 0;
    int boolean = 0;
    for(; coeff[k] != '\0' || exp[k] != '\0';)
    {
        if(coeff[k] == 1 && exp[k] == '\0')
        {
            s[j] = '1';
            j++;
        }
        else if(coeff[k] == -1 && exp[k] == '\0')
        {
            s[j - 1] = '-';
            s[j] = '1';
            j++;
        }
        else if(coeff[k] == 0)
        {
            /* do nothing */
        }
        else
        {
            l = 0;
            char temp[ASIZE];
            char temp2[ASIZE];

            if(coeff[k] == 1)
            {
                /* don't do anything. Since coefficient 1 should not be printed */
            }
            else
            {
                if(coeff[k] == -1 && j != 0)
                {
                    s[j - 1] = '-';
                }
                else
                {
                    toCharArray(coeff[k], temp); /* If coeff[k] is not just a digit but a number > 9*/
                    for(; temp[l] != '\0'; l++)
                    {
                        /* s[j - 1] is initially '+' but since the next coefficient is negative '+' should not be printed but instaead '-' should be there*/
                        if((temp[l] == '-' && j != 0)) /*j!= 0 because if first coefficient is negative then s[j - 1] is out of bound*/
                        {
                            s[j - 1] = temp[l];
                        }
                        else
                        {
                            s[j] = temp[l];
                            j++;

                        }
                    }
                }
            }
            if(exp[k] == 0)
            {
                /* don't do anything */
            }
            else
            {
                s[j] = 'x';
                j++;
                if(exp[k] == 1)
                {
                    /* don't do anything */
                }
                else
                {
                    s[j] = '^';
                    j++;
                    l = 0;
                    toCharArray(exp[k], temp2);
                    for(; temp2[l] != '\0'; l++)
                    {
                        s[j] = temp2[l];
                        j++;
                    }
                }
            }
            /* print '+' only if there is a next element and if next element is 0 then no need to print it*/
            if(coeff[k + 1] != '\0' || exp[k + 1] != '\0')
            {
                s[j] = '+';
                j++;
            }
        }
        k++;
    }
    if(j == 0)
    {
        s[j] = '0';
        s[j + 1] = '\0';
    }
    else
    {
        s[j] = '\0';
    }


}  /* end polynom_to_string */

/* This method converts an integer into char Array */
void toCharArray(int n1, char *s)
{
    char buffer[ASIZE];
    int i = 0;
    int len;
    int booleanIsNeg = 0;

    /* If integer is 0*/
    if(n1 == 0)
    {
        s[0] = '0';
        s[1] = '\0';
    }
    else
    {
        if(n1 < 0) /* negative number */
        {
            booleanIsNeg = 1;
            n1 = -1 * n1;
        }

        for(; n1 != 0; i++)
        {
            buffer[i] = n1 % 10 + '0';
            n1 = n1 / 10;
        }
        if(booleanIsNeg == 1)
        {
            buffer[i] = '-';
            i++;
        }
        buffer[i] = '\0';
        len = i;
        int j = 0;
        /* reverse the buffer array*/
        for(; j != len; j++)
        {
            s[j] = buffer[i - 1];
            i--;
        }
        s[j] = '\0';
    }
}

/*
  Evaluate the polynomial for the value of x and store the result p(x) in variable result.
 */
void eval_polynom(int coeff[ ], int exp[ ], double x, double *result )
{
    int j = 0;
    double dupx = x;
    *result = 0;

    for(; coeff[j] != '\0' || exp[j] != '\0'; j++)
    {
        int expo = exp[j];
        if(expo == 0)
        {
            x = 1;
        }
        else
        {
            if(expo > 0)
            {
                if(expo == 1)
                {
                    x = x;
                }
                else
                {
                    while(expo != 1)
                    {
                        x = x * dupx;
                        expo--;
                    }
                }
            }
            else
            {
                if(expo == -1)
                {
                    x = 1 / x;
                }
                else
                {
                    while(expo != -1)
                    {
                        x = x * dupx;
                        expo++;
                    }
                    x = 1 / x;
                }
            }
        }
        double intermediate = coeff[j] * x;
        *result = *result + intermediate;
        x = dupx;
    }

}  /* end eval_polynom */



/*
  Add two polynomials and the result is stored in the first polynomial (arrays co1[] and ex1[]).
 */
void add_polynom( int co1[ ], int ex1[ ], int co2[ ], int ex2[ ] )
{
    sort(co1, ex1);
    sort(co2, ex2);

    int co2b[ASIZE];
    int ex2b[ASIZE];

    len = 0;
    int length1 = 0; /* to store length of polynomial 1 */
    int length2 = 0; /* (to store length of co2 which is same as ex2) || (to store length of plynomial 2) */

    while(co1[length1] != '\0'|| ex1[length1] != '\0')
    {
        length1++;
    }

    while(co2[length2] != '\0'|| ex2[length2] != '\0')
    {
        length2++;
    }

    int index = 0;
    while(index < length2)
    {
       co2b[index] = co2[index];
       index++;
    }

    index = 0;
    while(index < length2)
    {
       ex2b[index] = ex2[index];
       index++;
    }


    int i = 0;
    int k = 0;

    if(length1 == 0)
    {
        co1[length1] = co2[length2];
        length1++;
    }
    /* doing addition of the exponents with 0 first*/
    if(ex1[length1 - 1] == ex2[length2 - 1] && ex1[length1 - 1] == 0)
    {
        int d = co1[length1 - 1] + co2[length2 - 1]; /* add the two coffecients of the same exponents */
        co1[length1 - 1] = d;
        co2[length2 - 1] = 0; /*turning the coefficient into 0 since its addition is done*/
    }

    for(; co1[i] != '\0' || ex1[i] != '\0'; i++)
    {
        int j = 0;
        for(; j < length2; j++)
        {
            if(ex1[i] == ex2[j] && ex1[i] != 0)
            {
                int d = co1[i] + co2[j]; /* add the two coffecients of the same exponents */
                co1[i] = d;
                co2[j] = 0; /*turning the coefficient into 0 since its addition is done*/
                ex2[j] = 0; /*turning the exponent into 0 since its addition is done*/
            }
        }
    }

    /* adding remaining elements of second polynomial to first one*/
    for(; k < length2; k++)
    {
        if(co2[k] != 0 || ex2[k] != 0)
        {
            co1[i] = co2[k];
            ex1[i] = ex2[k];
            i++;
        }
    }

    ex1[i] = '\0';
    co1[i] = '\0';
    len = i;

    index = 0;
    while(index < length2)
    {
       co2[index] = co2b[index];
       index++;
    }

    index = 0;
    while(index < length2)
    {
       ex2[index] = ex2b[index];
       index++;
    }
    sort(co1, ex1);


}  /* end add_ polynom */


/************************** END OF FILE ***************************/




<file_sep>/A2/Q2 (1)/menu
#!/bin/sh
# EECS2031 - asg2
# Filename: menu
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

echo "=================== MENU ==================="
echo "s: Search for a word"
echo "c: Count lines, words, characters"
echo "f: List all ordinary files in current directory"
echo "v: View content of a file"
echo "d: Double spacing"
echo "a: Add line numbers"
echo "l: Display specified lines in file"
echo "h: Help / Display this menu"
echo "r: Clear the screen"
echo "q: Quit the program"
echo "============================================"<file_sep>/Labs/Lab 6/calc.c
/***********************************
* EECS 2031 - Lab 6
* Filename: calc.c
* Author: Last name, first name
* Email: Your preferred email address
* Login ID: Your EECS login ID
************************************/


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


/*****  YOU MAY ADD YOUR OWN FUNCTION(S) HERE.  *****/
int stringToInt(char a[])
{
    int c, sign, offset, n;

  if (a[0] == '-') {  // Handle negative integers
    sign = -1;
  }

  if (sign == -1) {  // Set starting position to convert
    offset = 1;
  }
  else {
    offset = 0;
  }

  n = 0;

  for (c = offset; a[c] != '\0'; c++) {
    n = n * 10 + a[c] - '0';
  }

  if (sign == -1) {
    n = -n;
  }

  return n;
}


/* Implement a simple calculator.
   Input: two operands and one operator as command-line arguments.
   Output: the result displayed on the standard output.
 */

void main( int argc, char *argv[] )
{
    int result = 0;  /* stores the result of the arithmetic operation */


    /*****************************************/
    /***** ADD YOUR CODE BELOW THIS LINE *****/

    if(argc <= 1)
    {
        printf("Usage: calc [operand_1] [operator] [operand_2]\n");
    }
    else
    {
        int operand1 = stringToInt(argv[1]);
        int operand2 = stringToInt(argv[3]);
        char operator =  argv[2][0];
        if(operator == '+')
        {
            result = operand1 + operand2;
        }
        else if(operator == '-')
        {
            result = operand1 - operand2;
        }
        else if(operator == 'x')
        {
            result = operand1 * operand2;
        }
        else if(operator == '/')
        {
            result = operand1 / operand2;
        }
        else
        {
            result = operand1 % operand2;
        }




        /***** ADD YOUR CODE ABOVE THIS LINE *****/
        /*****************************************/

        /**** DO NOT ADD OR CHANGE ANYTHING BELOW THIS LINE ****/

        printf( "%d\n", result );
    }

}



<file_sep>/Labs/lab8/q2/phone
#!/bin/sh
echo -n "Enter the name to search: "
read name
grep -i $name phone_book.txt
<file_sep>/A2/Q2 (1)/fdisplay
#!/bin/sh
# EECS2031 - asg2
# Filename: fdisplay
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

echo -n "Enter the file name: "
read filename

if test ! -f $filename
then
echo "File '$filename' does not exist."

elif test ! -r $filename
then 
echo "File '$filename' is not readable."

else

echo -n "Enter option (e, p, f, l): "
read varname

until test $varname = e || test $varname = E || test $varname = p || test $varname = P || test $varname = f || test $varname = F || test $varname = l || test $varname = L
do
echo "Invalid option"
echo -n "Enter option (e, p, f, l): "
read varname
done

if test $varname = e || test $varname = E
then
	cat $filename
elif test $varname = p || test $varname = P
then
	cat $filename | more

elif test $varname = f || test $varname = F
then
	head $filename

elif test $varname = l || test $varname = L
then
	tail $filename
else
	echo "Invalid option" 
fi

fi<file_sep>/A2/Q2 (1)/isearch
#!/bin/sh
# EECS2031 - asg2
# Filename: isearch
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

echo -n "Enter the file name: "
read filename

if test ! -f $filename
then
echo "File '$filename' does not exist."

elif test ! -r $filename
then echo "File '$filename' is not readable."

else

echo -n "Enter the word to search for: "
read searchword

echo -n "Case sensitive (y/n)? "
read varname

until test $varname = "y" || test $varname = "Y" || test $varname = "n" || test $varname = "N"
do
echo "Invalid option"
echo -n "Case sensitive (y/n)? "
read varname
done

	if test $varname = "y" || test $varname = "Y"
	then
  	grep $searchword $filename

	elif test $varname = "n" || test $varname = "N"
	then
	grep -i $searchword $filename

	fi

	if test $? -ne 0
	then
  	echo "Word '$searchword' not found."
	fi
fi
<file_sep>/Labs/lab8/q2/mkpub2
#!/bin/sh
for name in $*
do
mkpub $1
shift
done	

<file_sep>/Labs/Lab7/marks.c
/***********************************
* EECS 2031 - Lab 7
* Filename: marks.c
* Author: Last name, first name
* Email: Your preferred email address
* Login ID: Your EECS login ID
************************************/

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


void main( int argc, char *argv[] )
{


    /*****************************************/
    /***** ADD YOUR CODE BELOW THIS LINE *****/

    if(argc < 3)
    {
        printf("Usage: marks [input_file] [output_file]\n");
    }
    else
    {
        FILE *ifile, *ofile;
        ifile = fopen( argv[1], "r" );
        if ( ifile == NULL )
        {
            printf("File empty!\n");
            exit(1);
        }
        ofile = fopen( argv[2], "w" );
        if ( ofile == NULL )
        {
            printf("No write permission!\n");
            exit(1);
        }

        char fname[30], lname[30];
        int asg1;
        int asg2;
        float avg;
        while ( fscanf( ifile, "%s %s %d %d", &fname, &lname, &asg1, &asg2 ) != EOF )
        {
            avg = (float) (asg1 + asg2) / 2;
            fprintf( ofile, "%s %s %d %d %.1f\n", fname, lname, asg1, asg2, avg);
        }

    }





    /***** ADD YOUR CODE ABOVE THIS LINE *****/
    /*****************************************/

}  /* end main */


<file_sep>/Labs/lab8/q2/calc~
#!/bin/sh

if test $2 = "+"
then
echo `expr $1 + $3`

elif test $2 = "-"
then
echo `expr $1 - $3`

elif test $2 = "x"
then
echo `expr $1 * $3`

elif test $2 = "/"
then
echo `expr $1 / $3`

else
echo `expr $1 % $3`

fi
<file_sep>/README.md
# 2031-C-and-shell-scripting<file_sep>/A1/Q1- Polynomial/poly.h
/***********************************
* EECS2031 - Assignment 1
* Filename: poly.h
* Author: <NAME>
************************************/

#include <stdio.h>
#define ASIZE 50
<file_sep>/Labs/lab8/q2/phone2
#!/bin/sh
grep -i $1 phone_book.txt<file_sep>/A2/Q2 (1)/prtlines
#!/bin/sh
# EECS2031 - Lab 8
# Filename: prtlines
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

echo -n "Enter file name: "
read filename

if test ! -f $filename
then
echo "File '$filename' does not exist."

elif test ! -r $filename
then echo "File '$filename' is not readable."

else
size=`wc -l < $filename`
echo "File '$filename' has $size lines."
echo -n "From line: "
read x
while test `expr $x` -le `expr 0` || test `expr $x` -gt `expr $size`
do
	echo "Invalid line number"
	echo -n "From line: "
	read x
done

echo -n "To line: "
read y
while test `expr $y` -le `expr 0` || test `expr $y` -gt `expr $size` || test `expr $y` -lt `expr $x`
do
	echo "Invalid line number"
	echo -n "To line: "
	read y
done
last=`expr $y - $x + 1`
count=1

while test `expr $count` -le $last
do

echo -n "$x: "
echo -n "`head -$x phone_book.txt | tail -1`"
echo
count=`expr $count + 1`
x=`expr $x + 1`
done

fi
<file_sep>/Labs/Lab4/lab4b.c
/***********************************
* EECS2031 - Lab 4		   
* Filename: lab4b.c		  	
* Author: Last name, first name	    
* Email: Your email address	 	
* Login ID: Your EECS login ID 		
************************************/


#include <stdio.h>

#define MAX_SIZE 100

main() {

  char my_strg[ MAX_SIZE ];
  double my_number = 0.0;


  /********** Fill in your code here. **********/

  int c, i = 0;
  int n = 0;  /* number of fractional digits */
  double frac = 0.0; 

  /* Input a string */
  while ( ( c = getchar() ) != '\n' )
    my_strg[ i++ ] = c;
  my_strg[ i ] = '\0';

  /* Convert the string to a double */
  for( i = 0; my_strg[ i ] != '.'; i++ )
    my_number = my_number * 10 + ( my_strg[ i ] - '0' );

  /* At this point, my_strg[i] == '.' and my_number contains the integer part. */
  /* Process the fractional part */
  for( i++, n = 0; my_strg[ i ] != '\0'; i++, n++ )
    frac = frac * 10 + ( my_strg[ i ] - '0' ); 

  /* At this point, my_strg[i] == '\0' */
  /* Adjust the fractional part */
  for( i = 1; i <= n; i++ )
    frac /= 10;  

  my_number += frac;
  
  /*********************************************/

  printf( "%.6f\n", my_number );
}



<file_sep>/Labs/lab8/q2/mkpub2~
#!/bin/sh
for name in $*
do
shift
mkpub $0
done	

<file_sep>/A2/Q2 (1)/myutil2 not used
#!/bin/sh
# EECS2031 - asg2
# Filename: myutil
# Author: <NAME>
# Email: <EMAIL>
# Login ID: nehamo

menu
echo
echo -n "Enter command: "
read command

until test $command = q || test $command = Q
do

if test $command = s || test $command = S
then
isearch

elif test $command = c || test $command = C
then
icount

elif test $command = f || test $command = F
then
allfiles

elif test $command = v || test $command = V
then
fdisplay

elif test $command = d || test $command = D
then
doublesp

elif test $command = a || test $command = A
then
addlines

elif test $command = l || test $command = L
then
prtlines

elif test $command = h || test $command = H
then
menu

elif test $command = r || test $command = R
then
clear

else
echo "Invalid command"
fi

echo
echo -n "Enter command: "
read command
done

if test $command = q || test $command = Q
then
exit 1
fi
<file_sep>/A2/Q2 (1)/doublesp
#!/bin/sh
# EECS2031 - asg2
# Filename: doublesp
# Author: <NAME>
# Email: <EMAIL>
# Login ID: york18

echo -n "Enter input file name: "
read fileinput

if test ! -f $fileinput
then
echo "File '$fileinput' does not exist."

elif test ! -r $fileinput
then echo "File '$fileinput' is not readable."

else

echo -n "Enter output file name: "
read fileoutput

if test -f $fileoutput && test ! -w $fileoutput
then
echo "File '$fileoutput' not writable."
exit 1
fi

if test ! -f $fileoutput
then
	touch $fileoutput
	size=`wc -l < $fileinput`
	count=1

	while test `expr $count` -le `expr $size`
	do
	(head -$count $fileinput | tail -1) >> $fileoutput
	(echo;echo) >> $fileoutput
	count=`expr $count + 1`
	done

elif test -f $fileoutput
then
	echo "File '$fileoutput' exists."
	echo -n "Append to it (y/n)? "
	read append

	until test $append = "y" || test $append = "Y" || test $append = "n" || test $append = "N"
	do
	echo "Invalid option"
	echo -n "Append to it (y/n)? "
	read append
	done

	if test $append = y || test $append = Y
	then
		size=`wc -l < $fileinput`
		count=1

		while test `expr $count` -le `expr $size`
		do
		(head -$count $fileinput | tail -1) >> $fileoutput
		(echo;echo) >> $fileoutput
		count=`expr $count + 1`
		done

	elif test $append = "n" || test $append = "N"
	then
		exit 1
	else
		echo "Invalid option"
	fi

fi
fi
