User Tools

Site Tools


opus:spring2012:rmatsch:part1

Part 1

Entries

Entry 1: January 25, 2012

On january 25 I experienced compressing and uncompressing files using gzip and gunzip. Gzip and gunzip are utilities you can use to allow for easy compressing of files and extracting of files. First gzip is used for compressing files. This utility works by opening up a command prompt and typing gzip(space)filesname.txt then press enter. This just compressed your file. To check to see if it is compressed type ls command on a command prompt and you will see filename.txt.“gz” meaning it was compressed with gzip utility. Now to unzip the compressed file type gunzip filename.txt and it will uncompressed to the current directory you are in. To check this issue ls command and see that your file does not have .gz after it. This is one way of easy compression and extracting files which is very useful utility to know.

Entry 2: January 26, 2012

chmod is a utility that allows you to change permissions on a file. My reason for writing about this utility is because changing permissions via the symbolic way is messy. When using chmod to change the permission you first need to understand a few things. First there are different permissions and they are: User (u) the user that owns the file, group (g) which is the group that owns the file and then other (o) which is everyone else on the system. Each of these has the read ® write (w) and execute/search(x) permission attached to each. An example would be rwxr-xr-x to rmatsch the answer.txt file. The first three letters correspond to the permission of the owner of the file then the next three are the permissions for group and then three more for other. Notice how there is a dash where a letter would be. This is because that particular group, owner,or other does not have that privilege. Also access to rwx for owner means access of (7). r-x means group access (5) and –x means other has access (1). This calculation is done by attributing the value 4 for read, 2 for write, and 1 for execute/search. If you add rwx you get (7). I should also mention the reason for 0-7 is because this is assigning of permissions by octal. For example, to assign read/ write/ execute permission for owner, read/execute for group and execute for other or commonly known as the “world” you would type in at the command prompt chmod 751 the answer.txt which would change the permission to the example listed above. The significant using octal for changing permission of files is because it takes longer changing files via symbolic notation, saving time and in the business world money. Changing permission via symbolic example: “Chmod o+rwx filename.txt” just sets other(o) to full permission read write and execute. A simple command such as “chmod 644 filename.txt” sets all three very quickly and less error is likly while typing.

Entry 3: Febuary 15, 2012

            root
              |
            home
              |
           rmatsch
              |
   ___________________________
  |      |      |      |      |
 bin    src   file.c    lab2  hello.c
         |
     __________
    |    |     |
 cprog  unix   submit
    |
    |____________________
    |          |         |
Contact.info   var2.c   array.c

Entry 4: Febuary 17, 2012

To access unconventional names there is three basic things to remember. When looking up files named unconventionally is not very fun thankfully you can use three characters to help with this. the characters are *,\, and ” ”. if given the file *?? ghty.file normal cat utility would when run on this would cat *?? And then cat ghty.file separately but if you were to type cat *??* you would be able to access the content. Another way use the \ to escape the following character so you would type cat *??\(space)ghty.file and then hit enter. Finally another quick and easy way is to use ” ”. This looks like this cat “*?? ghty.file” and then you can access the content.

* \ ” ” or ' '

Keywords

Cprog Keywords

Standard I/O (STDIO, STDOUT, STDERR)

■ Header Files (Local and System), C Standard Library (Libc), Libraries……X

■ arithmetic (equations, operators)…..X

■ logic and operators (and, or, not, xor)

■ Variables (types, ranges, sizes)…..X

■ Scope (Block, Local, Global, File)

■ Pointers (address of, assignment, dereferencing)…..X

■ Type Casting

■ Selection Structures (if, case/switch)……X

■ Repetition/Iteration Structures (for, while, do while)….X

■ Arrays (standard notation, pointer arithmetic, single-dimensional, multi-dimensional)…..X

■ File Access (Read, Write, Append)…..X

■ Structures (Declaration, Accessing Elements, Pointers to)

■ typedef, enum, union

■ Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments

■ Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)

■ I/O Streams (cin, cout, cerr, stream operators) [C++]

■ Namespaces [C++]

■ Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]

■ Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]

■ Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]

■ Overloading (Functions, Operators) [C++]

■ Exception Handing (throw, try, catch) [C++]

■ Templates, STL (Standard Template Library) [C++]

Variables

Definition

Variables are storage containers which can be permanent but most of the time they vary or change throught a computer program.

Demonstration

Variables have 3 basic properties.First is name, in order to use a variable you must have declare a name for the variable to call it by. secondly you must select a data type such as type “interger” or “char”. Thirdly is the size of this container you want the variable to be. Thankfully this is already determined by the data type you have established so the work is already done. The data type selected can hold a certain amount of data. Below is code for a program to show you the different sizes of a data types there ranges the unique values they can have.I must also mention that upon selection of a data type there are signed and unsigned variables also. Signed variables can handle negative along with positive values and unsigned variables can handle only positive values.

Code :

#include <stdio.h>
#include <math.h>
int main()
{
        // declare variables
        unsigned char uc = 0;
        signed char sc = 0;
        signed short int ssi = 0;
        unsigned short int usi =0;
        signed long int sli = 0;
        unsigned long int uli =0;
        signed long long int slli = 0;
        unsigned long long int ulli = 0;
        signed int si  = 0;
        unsigned int ui = 0;
        unsigned long long int quantity = 0;
 
        //display info for unsigned char data type
        printf("Unsigned char is %u bytes\n", sizeof(uc));
        printf("The range of an unsigned char is %hhu to %hhu\n", uc, (uc-1));
        quantity=(unsigned char)(uc-1) + 1;/* unsigned char -1 = 255 +1 for all unique values*/
         printf("An unsigned char can store %llu unique values\n\n", quantity);
        //display info for signed char data type
        printf("Signed char is %d bytes\n", sizeof(sc));
        quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); /*2 raised to the power of 8 times data type in  bytes */
        printf("The range of a signed char is %hhd to %hhd\n", (sc-(quantity/2)), (sc+(quantity/2)-1));
         printf("A unsigned char can store %llu unique values\n\n", quantity);
 
        printf("Unsigned short int is %u bytes\n", sizeof(usi));
        quantity = (unsigned long long int)pow(2, (sizeof(usi)*8));
         printf("The range of a unsigned short int is %u to %llu\n", usi, ((quantity)-1));
         printf("An unsigned short int can store %llu unique values\n\n", quantity);
 
        printf("Signed short int is %d bytes\n", sizeof(ssi));
        quantity = (unsigned long long int)pow(2, (sizeof(ssi)*8));
       printf("The range of a signed short int is %lld to %lld\n", (ssi-(quantity/2)), (ssi+(quantity/2)-1));
        printf("A signed short int can store %llu unique values\n\n", quantity);
 
 printf("Signed int is %d bytes\n", sizeof(si));
        quantity = (unsigned long long int)pow(2, (sizeof(si)*8));
         printf("The range of a signed int is %lld to %lld\n", (si-(quantity/2)), (si+(quantity/2)-1));
        printf("A signed int can store %llu unique values\n\n", quantity);
 
        printf("Unsigned int is %u bytes\n", sizeof(ui));
        quantity = (unsigned long long int)pow(2, (sizeof(ui)*8));
         printf("The range of a unsigned int is %llu to %llu\n", ui,((quantity)-1));
        printf("An unsigned int can store %llu unique values\n\n", quantity);
 
        printf("Signed long int is %d bytes\n", sizeof(sli));
        quantity = (unsigned long long int)pow(2, (sizeof(sli)*8));
         printf("The range of a signed long int is %lld to %lld\n", (sli-(quantity/2)), (sli+(quantity/2)-1));
        printf("A signed long int can store %llu unique values\n\n", quantity);
 
        printf("Unsigned long int is %u bytes\n", sizeof(uli));
        quantity = (unsigned long long int)pow(2, (sizeof(uli)*8));
         printf("The range of a unsigned long long int is %llu to %llu\n", uli,((quantity)-1));
        printf("An unsigned long int can store %llu unique values\n\n", quantity);
 
 
         printf("Signed long long int is %d bytes\n", sizeof(slli));
        quantity = (unsigned long long int)pow(2, (sizeof(slli)*8));
        printf("The range of a signed long long int is %lld to %lld\n", (slli-(quantity/2)), (slli+(quantity/2)-1));
        printf("A signed long long int can store %llu unique values\n\n", quantity);
 
        printf("Unsigned long long int is %u bytes\n", sizeof(ulli));
        quantity = (unsigned long long int)pow(2, (sizeof(ulli)*8));
         printf("The range of a unsigned long long int is %llu to %llu\n", ulli,((quantity)-1));
        printf("An unsigned long long int can store %llu unique values\n\n", quantity);
 
 
return(0);
}

What command line looks like when program is run.

lab46:~/src/cprog$ ./project0
Unsigned char is 1 bytes
The range of an unsigned char is 0 to 255
An unsigned char can store 256 unique values

Signed char is 1 bytes
The range of a signed char is -128 to 127
A unsigned char can store 256 unique values

Unsigned short int is 2 bytes
The range of a unsigned short int is 0 to 65535
An unsigned short int can store 65536 unique values

Signed short int is 2 bytes
The range of a signed short int is -32768 to 32767
A signed short int can store 65536 unique values

Signed int is 4 bytes
The range of a signed int is -2147483648 to 2147483647
A signed int can store 4294967296 unique values

Unsigned int is 4 bytes
The range of a unsigned int is 0 to 4294967295
An unsigned int can store 4294967296 unique values

Signed long int is 8 bytes
The range of a signed long int is -9223372036854775807 to 9223372036854775806
A signed long int can store 18446744073709551615 unique values

Unsigned long int is 8 bytes
The range of a unsigned long long int is 0 to 18446744073709551614
An unsigned long int can store 18446744073709551615 unique values

Signed long long int is 8 bytes
The range of a signed long long int is -9223372036854775807 to 9223372036854775806
A signed long long int can store 18446744073709551615 unique values

Unsigned long long int is 8 bytes
The range of a unsigned long long int is 0 to 18446744073709551614
An unsigned long long int can store 18446744073709551615 unique values

Pointers

Definition

variables are seen as memory cells that can be accessed using their identifiers (aka pointers). Because we did not have to care about the physical location of our data within memory, we can simply used its identifier when we need to refer to the variable.

Demonstration

Below is code to help understand what pointers acually do.

#include <stdio.h>
int main()
{
        // a is initiallly set to zero
        int a = 0;
        int * b; /* b is declared as a pointer variable by star b */
        b = &a; /* b is assigned the adress of a */
        *b = 12; /* what ever b is pointing at is now set equal to 12 not b itself */
 
        printf("a contains %u \n", a );
 
        printf("a's address is 0x%x\n", &a );
 
        printf("b contains %u \n", *b);
      // b contains the value stored at what b is pointing to. (the container or another variable)
        printf("b points to 0x%x\n", b);
 
        printf("b's addres is 0x%x\n", &b);
 
        return(0);
}
lab46:~/src/cprog$ ./var2
a contains 12
a's address is 0xe5a3f33c
b contains 12
b points to 0xe5a3f33c
b's addres is 0xe5a3f330

arithmetic

Definition
+ Adding binary operator, adds two operands to get a sum, (addend +adend = sum
- Subtract binary operator, inverse of adding, (minuend -subtrahend = difference)
% Modulus takesremainder after an integer division
++ means +1
-- means -1
* Multiply binary operator (multiplicand times multiplier = product)
/ Divide binary operator(dividen / divisior = quotient)
Demonstration
c=5
b=3
p=5
q=5

c-b=a = 5-3=2 a =2 
c+b=a = 5+3=8 a =8
c*b=a = 5*3=15 a =15
x=p/q = 5/5=1 a =1

c++ means c= to 5 plus one =6

cprog Keyword 4

Header files

Definition

Header Files are files that are incoporated in c code to allow you added funtionality such as use of funtions or expressions.

Demonstration

#include <stdio.h> #include <stdlib.h> code to demonstrate

#include <stdlib.h>
#include <stdio.h>
 
int main()
{
    return(0);
}

cprog Keyword 5

Arrays

Definition

Arrays can be thought of as sequentialy ordered containers. The ability to take a big piece of data such as string and break it up into individual pieces to be manipulted as needed. because arrays store data in “numbered containers” arrays are a good thing to know.

Demonstration
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
        unsigned char i;
 
        if (argc<2)
        {
                printf("%8s must be run with 1 or \
        more arguments, you only provide %hhu\n", *(argv+0),(argc-1));
                exit(1);
        }
        printf("pleas enter a message to be ciphered")
         for(i=0;i<argc; i++)
        {
                printf("argv[%hhu]: %s \n",i,*(argv+i));
        }
        return(0);
}
./acs h e y t h i s i s a n a r r a y
you ran this program with 17 arguments, they are:
argv[0]: ./acs
argv[1]: h
argv[2]: e
argv[3]: y
argv[4]: t
argv[5]: h
argv[6]: i
argv[7]: s
argv[8]: i
argv[9]: s
argv[10]: a
argv[11]: n
argv[12]: a
argv[13]: r
argv[14]: r
argv[15]: a
argv[16]: y

multidemensional array would look similar to this

   0 1 2 3
0  y r e d
1  a b h o 
2  f k z p 
3  t u m l

argv[1][2]:k

cprog Keyword 6

Selection Structures (if, case/switch)

Definition

selection structure is a order of sequence of check statments (conditional statements) that are true or false. If the stament is true then do somthing.

Demonstration
 if (in == NULL){
                fputs("please enter a message to cipher:\n", stdout);
                fgets(msg, sizeof msg, stdin);
                fprintf(nf, "%s", msg);
                fclose(nf);
                nf = fopen("nofile.txt", "r");
                letter1 = fscanf(nf,"%c", &letter);
        }else{
                 letter1 = fscanf(in, "%c", &letter);
 
        }if (key == NULL){
                printf("please enter a key to encipher with :\n");
                scanf("%d", &keyvalue);
        }else{
                fscanf(key,"%d",&keyvalue);

cprog Keyword 7

Repetition/Iteration Structures (for, while, do while)

Definition

Repetitive/iteration structures or loops are a statement which allows code to be repeatedly executed until a condition is meet or can be instructed to “do” something while this condition is true.

Demonstration
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
        unsigned char i;
 
        if (argc<2)
        {
                printf("%8s must be run with 1 or \
        more arguments, you only provide %hhu\n", *(argv+0),(argc-1));
                exit(1);
        }
        printf("you ran this program with %hhu arguments, they are:\n", argc);
         for(i=0;i<argc; i++)/* Condition to be checked */
        {
                printf("argv[%hhu]: %s \n",i,*(argv+i));
        }
        return(0);
}

another example

 while (letter1 != EOF)
        {
                if((letter >= 'A') && (letter <= 'Z'))
                        letter = (((abs(letter - 65) + keyvalue)%26)+65);
                else if((letter >= 'a') && (letter <= 'z'))
                        letter = (((abs(letter - 97) + keyvalue)%26)+97);

                fprintf(out,"%c",letter);
                if (in == NULL){
                        letter1 = fscanf(nf, "%c", &letter);
                }else{
                        letter1 = fscanf(in, "%c", &letter);
                }

cprog Keyword 8

File access

Definition

File Access is when you read from, write to, or append to a file. the program can read write or append to a file.

Demonstration

Demonstration of the chosen keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(){
        char letter1=0;
        char msg[250];
        FILE *in, *out, *key,*nf;
        char letter = 0;
        int keyvalue;
 
        nf = fopen("nofile.txt", "w");
        in = fopen("message.txt", "r");
        out = fopen("cipher.txt", "w");
        key = fopen("key.txt","r");
 
        if (in == NULL){
                fputs("please enter a message to cipher:\n", stdout);
                fgets(msg, sizeof msg, stdin);
                fprintf(nf, "%s", msg);
                fclose(nf);
                nf = fopen("nofile.txt", "r");
                letter1 = fscanf(nf,"%c", &letter);
        }else{
                 letter1 = fscanf(in, "%c", &letter);
 
        }if (key == NULL){
                printf("please enter a key to encipher with :\n");
                scanf("%d", &keyvalue);
        }else{
                fscanf(key,"%d",&keyvalue);
        }
        while (letter1 != EOF)
        {
                if((letter >= 'A') && (letter <= 'Z'))
                        letter = (((abs(letter - 65) + keyvalue)%26)+65);
                else if((letter >= 'a') && (letter <= 'z'))
                        letter = (((abs(letter - 97) + keyvalue)%26)+97);
  fprintf(out,"%c",letter);
                if (in == NULL){
                        letter1 = fscanf(nf, "%c", &letter);
                }else{
                        letter1 = fscanf(in, "%c", &letter);
                }
 
        }if (in == NULL){
                fclose(nf);
        }else{
                fclose(in);
        }
        if (key != NULL){
                fclose(key);
        }
 
 
        //fclose(in)
        fclose(out);
        //fclose(nf);
        return(0);
}
lab46:~/src/cprog$ cat cipher.txt
jpa
lab46:~/src/cprog$

lab46:~/src/cprog$ cat plain.txt
hey
lab46:~/src/cprog$

cprog Objective

cprog Objective

The course objective is for students to be able to write, compile code, use pointers and variables effectively and efficiently. Also this course is designed for students to gain a basic comprehension of memory such as various data types. Also obtain valuable debugging skills and demonstrate the ability to use logic and structure to solve problems. Develop solutions shown in c++ program language.

Method

To measure successful academic/intellectual achievement of this objective. students should be given a final project that incorporates various lessons learned through the course because an important part of intellectual achievement is applying what you leaned. Students should also be asked to write various programs on the spot and should be completed given sufficient time.

Measurement

Correctness - are things displayed when they are supposed to, were variables initialized etc. Design/efficiency- there is many ways to design a program but there may be better ways or more efficient ways. (Are the right size variables used?)

Logic- has a basic concept of logic (uses loop instead of 100 if statements) Other- Does the program do what it was designed to do and accurately.

Analysis

Reflecting upon my results of the measurement to ascertain achievement of the course objective.

* How did you do? I did not do to bad but still have a lot to learn. * Is there room for improvement?yes * Could the measurement process be enhanced to be more effective? Yes * Do you think this enhancement would be efficient to employ? Yes * Could the course objective be altered to be more applicable? No

Reflecting on the measurements I did not do too bad, but of course have a lot to learn so there is much room for improvement.

unix Keywords

Local host….X

■ Remote host……X

■ Home directory……X

■ Current working directory…..X

■ Types of files (regular, directory, special)……X

■ File manipulation…..X

■ Text Processing…..X

■ The VI editor…..X

unix Keyword 1

Local host

Definition

Local host is is the standard hostname given to the address of the loopback network interface or the web address of the computer you are working on. Although local host can take different forms, the web address is simply your computer's identifier.

Demonstration

enter “http://127.0.0.1” into any web browser, and you will see a web page hosted by a web server on the same computer if one is running.

unix Keyword 2

Remote host

Definition

Remote hosts are computers that are not locally accessed. They are further away from where you are such as servers or public internet.

Demonstration

a computer connected to lab46.corning-cc.edu through ssh is an example of a remote host

unix Keyword 3

File Manipulation

Definition

file manipulation is the ability to control files such as moving them, removing them, copying them.

Demonstration
lab46:~/src/cprog
lab46:~/src/cprog$ touch file123
lab46:~/src/cprog$ cp file123 file2
lab46:~/src/cprog$ rm file123
rm: remove regular empty file `file123'? y
lab46:~/src/cprog$ mkdir file123
lab46:~/src/cprog$ rmdir file123
lab46:~/src/cprog$ mv file2 /tmp
lab46:~/src/cprog$
lab46:~/src/cprog$ cd /tmp
lab46:/tmp$ ls
A.txt                        cformansencryption.c  fishd.log.vcordes1     img--01315.htm  img--93112.asc        lost+found   nofile.txt  prog1x5
aptitude-rlott.11795:dKeQWo  fbarb.txt             fishd.socket.vcordes1  img--12835.htm  img-file-88471.c      mc-jbamper   plain.txt   prog1x5.c
aptitude-rlott.11860:1ABldB  file2                 hsperfdata_brobbin4    img--39027.htm  img-logout-04391.asc  mc-tedmist1  prog1x4.c   wierdfileiswierd
lab46:/tmp$

unix Keyword 4

Home directory

Definition

The home directory is your default directory. Whenever you open up a cmd prompt you are at your home directory.

Demonstration
        root
              |
            home
              |
           rmatsch
              |
   ___________________________
  |      |      |      |      |
 bin    src   file.c    lab2  hello.c
         |
     __________
    |    |     |
 cprog  unix   submit
    |
    |____________________
    |          |         |
Contact.info   var2.c   array.c
 login as: rmatsch
rmatsch@lab46.corning-cc.edu's password:
 __         _     _ _   __   . . . . . . . . . . . . . . . . . . . . . . . . .
|  |   __ _| |__ / | |_/ /   . Basic System Usage:  Type 'usage' at prompt   .
|  |__/ _` | '_ \\_  _/ _ \  . Events and News:     Type 'news' at prompt    .
|_____\__,_|_.__/  |_|\___/  . Broken E-mail?       Type 'fixmail' at prompt .
---------------------------  . Check Lab46 Mail:    Type 'alpine' at prompt  .
c o r n i n g - c c . e d u  . . . . . . . . . . . . . . . . . . . . . . . . .

 Lab46 is the Computer & Information Science Department's Student Development
 Server for Computer-related coursework, projects, and exploration.  For more
 information, please check out:
  .. .  .    .        .                .                .        .    .  . ..
 .  Lab46 Web Page:       http://lab46.corning-cc.edu/                       .
 .  Lab46 Help Form:      http://lab46.corning-cc.edu/help_request           .
 .  Help E-mail:          haas@corning-cc.edu or wedge@lab46.corning-cc.edu  .
  .. .  .    .        .                .                .        .    .  . ..
You have old mail.
Last login: Sat Mar  3 09:06:57 2012 from user-10bj433.cable.mindspring.com
lab46:~$

by typing pwd you are shown where you are at in relaton to directories. Also by typing in cd you are defaulted back to your home directory even if you are in another directory.

lab46:~$
lab46:~$ pwd
/home/rmatsch
lab46:~$ cd src
lab46:~/src$ cd
lab46:~$

unix Keyword 5

Current working directory

Definition

The current working directory is the directory that you're in.

Demonstration

The current working directory is the directory that you are in. Typing cd command with no arguments will change your current working directory to your home directory.The pwd command reveals the current working directory.

lab46:~$ cd src/unix
lab46:~/src/unix$ pwd
/home/rmatsch/src/unix
lab46:~/src/unix$ cd
lab46:~$ pwd
/home/rmatsch
lab46:~$

unix Keyword 6

Text Processing

Definition

Text Processing is a tool used to edit text, save text into files or from files but can also be used to change it other text files.

Demonstration

“nano” is a good example of a text processing.

lab46:~$
lab46:~$ nano hello.c
#include<stdio.h>

int main()
{
        printf("Hello, World !\n");
        return(0);
}

unix Keyword 7

Types of files (regular, directory, special)

Definition

There are three basic types of files, regular files like text, directories such as a file that contains other files within, and special files which can be programs.

Demonstration

hello1.c is a txt file,unix is a directory that contains other files,and hello1 is a compiled c code program.

lab46:~/src$ ls
Makefile  cprog  hello1  hello1.c  submit  unix
lab46:~/src$
lab46:~/src$ cd unix
lab46:~/src/unix$
lab46:~/src/unix$ ls
arc.tar.gz    cs1.txt  cs3.txt  cs5.txt   lab1.txt  lab3.txt  lab5.txt
contact.info  cs2.txt  cs4.txt  lab0.txt  lab2.txt  lab4.txt  shell
lab46:~/src/unix$

unix Keyword 8

Vi editor

Definition

The VI editor is a text editor with two modes one mode you can only insert, and in another mode you can only enter commands.

Demonstration

Demonstration of the chosen keyword.

lab46:~$ vim hello.c
#include<stdio.h>

int main()
{
        printf("Hello, World !\n");
        return(0);
}
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"hello.c" 7L, 76C  

to write to this file i must hit the i key for insert and then insert is diplayed to show you what mode you're in.

~
-- INSERT --  

to save changes go to command mode by hitting esc key and then typing :wq to quit without saving type :q!

unix Objective

unix Objective

Upon completion of this course, students should be able to show:

familiarity with the structure of UNIX systems the ability to accomplish/automate tasks exposure to command-line tools and utilities experience the connection between UNIX and C understanding of the UNIX philosophy exposure to Open Source concepts and ideals familiarity with important system concepts exposure to computer security understanding and use of pattern matching problem solving activities

Definition

The objective entails being familiar and comfortable in using unix to accomplish task. It also entails understanding basic understandings of unix.

Method

The method i use for measuring successful academic/intellectual achievement of this objective would be to be asked to complete various task to be completted in a timly mannor for a final.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

upon reflect my achievement of the particular course objective. i would do pretty good. Although i do pretty well there still could be room for improvement but am happy with the results.The measurement process could be enhanced to be more effective if more task were asked.I also believe these enhancement would be efficient to employ.however, what is asked for the objective is fine.

Experiments

Experiment 1

Question

What happens when you initialize a variable before the loop instead of initializing within the loop condition?

Resources

When using a loop in a program you have a condition that must be checked for the loop to start and end the loop. Usually the loop counting variable is initialized in the check condition of the loop.(common programming practice of loops)

Hypothesis

Before actually performing the experiment I believe that it will make no difference in how the program runs as long as the variable is not used before it is needed. Declaring global variables in a program are so you can use those variables throughout and at any part in the program so this includes the loop.

Experiment

I am going to test my hypothesis by developing a program which has a loop counting variable except i will initialize the variable in the start of the program instead of within the loop condition. My experiment will begin by first making a small program with initialization done within the loop condition. Then testing to make sure the program works and there are no bugs. Then I can proceed to initialize before the loop and not initialize with in the loop to see what happens.

Data

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) 
{
        unsigned char i;
        i=0;
        if (argc<2)
        {
                printf("%8s must be run with 1 or \
        more arguments, you only provide %hhu\n", *(argv+0),(argc-1));
                exit(1);
        }
        printf("you ran this program with %hhu arguments, they are:\n", argc);
        for(i<argc; i++)
        {
                printf("argv[%hhu]: %s \n",i,*(argv+i));
        }
        return(0);
}

Analysis======Conclusions

The out come of this exsperiment for the above code did not work out. Upon analysis of why i looked closer at the loop condition parameters.The loop condition wants three parameters. this is known because when you go to **manuel for the “for loop” or type “man 3 for” in command line and get this 'For' loop

“SYNOPSIS

     for start test next body

_

DESCRIPTION

     For  is  a  looping  command,  similar in structure to the C for statement.  The start, next, and body arguments must be Tcl command strings, and test is an
     expression string.  The for command first invokes the Tcl interpreter to execute start.  Then it repeatedly evaluates test as an expression; if  the  result
     is non-zero it invokes the Tcl interpreter on body, then invokes the Tcl interpreter on next, then repeats the loop.  The command terminates when test eval-
     uates to 0.  If a continue command is invoked within body then any remaining commands in   the current execution of body are skipped; processing continues  by
     invoking  the Tcl interpreter on next, then evaluating test, and so on.  If a break command is invoked within body or next, then the for command will return
     immediately.  The operation of break and continue are similar to the corresponding statements in C.  For returns an empty string."

A loop condition will not look anywhere else in the program for the variables it needs. The loop expects the initialization to be done within the loop condition.(Example)for(i=0;i<argc; i++). The loop counter will not add outside of the loop and pull the info back to check it expects the variable to be initialized within the parentheses.so by my experiment i have proved my hypothesis to be incorrect and there was more involved then initially thought.

Experiment 2

Question

What will happend when i change *4 to *3 when allocating sizeof char when dealing with arrays.

Resources

class notes.

Hypothesis

Based on what you've read with respect to my original posed question, i believe that in a program that is dependant on atleast 4 memory spaces when changed to 3 will cause a segmentation fault or possible incorrect results.my rayional for this is because when there is not eough space it will usually truncate but to low of memory i believ it will seg fault.

Experiment

by running a program that depends on space for array and taking space out to see what will come of the program.

Data

The prgram compiled but when running it segmentation faulted.

Analysis

Based on the data collected:

  • Was your hypothesis correct? yes based on the data collected i was correct.
  • Was your hypothesis not applicable?no my hypothesis was applicable.
  • Is there more going on than you originally thought? No there was not more going on then when i thought.

Conclusions

What can you based on the experiment i can ascertain that by running a program with less memory then required will cause a segmentation fault.

Experiment 3

Question

What will happen if i use single quotes in a prinf funtion?

Resources

C ansi book

Hypothesis

I believe you will obtain an err message when tyring to compile. the reason for my educated guess is because printf() usually prints whats is in double quotes.

Experiment

my exsperiment will entail creating a program that prints a mesage to stdout with quotes and then without quotes

Data

#include<stdio.h>

int main()
{
        printf("Hello, World !\n");
        return(0);
}

and the other code to run is:

#include<stdio.h>
int main()
{
        printf('Hello, World !\n');
        return(0);
}
lab46:~$ gcc -o hello hello.c
hello.c:5:16: warning: character constant too long for its type
hello.c: In function 'main':
hello.c:5: warning: passing argument 1 of 'printf' makes pointer from integer without a cast
/usr/include/stdio.h:339: note: expected 'const char * __restrict__' but argument is of type 'int'
lab46:~$

Analysis

Based on the data collected the code did compile so i was wrong but when running the program it segmentation faulted.

Conclusions

I was suprised it compiled at first but when giving the exsperiment more time to think i the reason for warning is because it was taking hello, world! and putting it into string so that explains warnings and segmentation fault.

opus/spring2012/rmatsch/part1.txt · Last modified: 2012/03/03 16:10 by rmatsch