======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 (r) 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===== {{page>cprogpart1&nofooter}} {{page>unixpart1&nofooter}} =====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 #include 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 ===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 #include int main() { printf("Hello, World !\n"); return(0); } and the other code to run is: #include 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.