Logged into Lab 46 http://www/haas/fall2013/cprog
Created a number guessing game in C, compiled with gcc.
Variable types
variables are defined by the number of bits they store information in
they can be signed and unsigned
unsigned variables cannot contain negative numbers
32 can fit into a char(half half int)
562 can fit into a short int
-32769 can fit into a long signed int
98 435 984 can fit into a long int
3.14 can fit into a float
-65 can fit into a signed char
31 415 926 535 897 can fit into a long long
-24764 can fit into a short signed int
this is a preprocessor directive
#include<stdio.h>
It finds this header file in the standard location and copies and pastes the contents
printf(); outputs a string to the screen. uses %u and similar to put variables in the output
scanf(); takes in a string and stores it in a variable. ended by whitespace
malloc(); must be casted to the size of the memory type
sizeof(); returns the bit size of a variable type
http://www.boutell.com/gd/manual2.0.33.html gd.h maual
Drew new images in drawprog.c
for(x=0,y=0;x>5, y>0;x++,y–)
Using xte from the xautomation package to move the mouse and type
Using xte with xpaint to draw stuff like a square
Made a program to play tetris randomly
'>' in the terminal redirects the STDOUT feed to something else
'2>' redirects STDERR
'»' and '2»' append instead of replace
'<' redirects STDIN stream
'»' logical right shift
'«' logical left shift
'&' bitwise AND
'|' bitwise OR
'~' bitwise NOT
'^' bitwise XOR
wrote 102logic.c wrote 102functions.c
& before a variable gives you the address of the variable
exceptions to functions standard setup -if() -for() -while() -return()
passing by value- the contents of the a variable in main is copied into the function(two separate memory locations with the same value)
passing by address(reference)- (the same memory address)
a procedure is a function that does not return a value
Structs!!!!! Heterogeneous composite
struct thing{ int a; char b[20]; float c; int d; short int e; }; typedef struct thing Thing; struct thing Stuff; stuff.a=12; stuff.b[3]=’A’;
Made a program called pix drawer.
It is a gd.h program and requires the -lgd (link to the gd library)
used on gcc to compile correctly
It creates a pix art picture using an array and GRECTS.
It takes in values from the user, putting them into an array
It then reads from the array using a series of nested for loops the draw the image
I created a text file of the data that I redirect into the program using » in bash
members of a class have access to the private member variables
The #ifndef statement creates a symbol only once to prevent the compiler from including the header file a whole bunch of times.
a pointer is dereferenced by * which brings you down a level. address of is given by & which brings you up a level.
BigNum *num=new BigNum(4); to use a constructor and pass in a parameter. the dot operator no longer works. use arrow →
-g when compiling
gdb ./yourprogram
list
run
break
print
display
next
step
continue
Started playing with the dig dug game that was written by a C/C++ class from several years prior
Improved collision detection system
Caused the enemy to move randomly
Created a Jewel that you can pick up
created a chest of which you can place the jewel
If the jewel makes it back to the chest, A good job Doge appears,
There are ten levels
learned more about cd and ls. Discovered ‘who’ command with help of “Unix for Beginning Mages”.
screen -r
absolute paths start with a root
pwd - “print working directory”
spells: ls, pwd, cd, mkdir, who, whereis, cal, date
windows vs. unix
pwd prints the working directory
mkdir creates a new directory
rmdir removes a directory if it is empty
rm -rf force removes a directory recursively, even if it is full. be careful
-learned vi, didn’t like it -edited .plan and .signature -finger command(tells more about user, including their plan) -PS1 variable in .bashrc changes prompt appearance -alias in .bashrc creates shortcut commands -created alias lll=’ls -alF|less’ -rm -rF(recursive, by Force) -timetravel with history command, use !number to redo the command -created script1.sh my first script -created script2.sh a number guessing game that loops, telling you if you are higher or lower until you guess correctly, written in bash
#!/bin/bash # #script2 my second script # pick=$RANDOM number=0 while [ “$pick” -ne “$number” ];do echo -n “Pick a number” echo read number if [ “$pick” -eq “$number” ]; then
echo "you win"
elif [ “$pick” -gt “$number” ]; then
echo "mystery number > $number, try again"
else
echo "mystery number < $number, try again"
fi done exit 0
Server software end in d short for daemon
spell list: grep jobs ps top-similar to ctrl alt delete whowatch-interactive who crontab -e kill command, takes -number as options nice - adjusts niceness level from -20 to 19, 19 is lowest priority pkill - pattern kill
. match any single symbol
* 0 or more of the previous( modification character)
\< match start of the word
\> match end of the word
$ match end of line
[ ] match one of the enclosed
[^ ] do not match any of the enclosed
( ) grouping
for1);do done while [ ] ;do done
if2);do fi
Interpreted Languages: HTML bash vbscript python javascript
Compiled C C++ Pascal Python Fortran
wrote plus, which takes one argument and adds it to input
Knowledge assessment week.
Brute is a brute. upgraded to elite Hakz0r.
used C programs, and used a script to orchestrate the whole system. A nice exercise in using multiple programs together in a top down approach
We made a script that counts the number of directories and files in a path and displays it as a histogram
</script> #!/bin/bash # # # if [ -z “$1” ]; then
echo -n "Enter a path: " read path chk=`ls $path 2>&1|grep 'No such file'|wc -l` if [ "$chk" -eq 1 ]; then path=`pwd` fi else path="$1"
fi echo $path cd $path max=0 for file in `ls -1d *`;do
c=`echo $file |wc -c` let data[$c]=${data[$c]}+1 if [ "$max" -lt "$c" ];then max=$c fi
done for3);do
printf "%2d |" $i if [ -z "${data[$i]}" ];then data[$i]=0 fi for((j=0;j<${data[$i]};j++))do echo -n "*" done
echo done </script>
documents worth reading HTTP RFC SMTP RFC RITA RFC -HAHA
telnet mail 25 HELO pimps.net MAIL FROM bitches@pimp.net RCPT user@lab46 DATA Subject:~~~~ ~~~~~~ ~~~~~~ ~~~~~~ .
telnet www 80 GET /
/sbin/ifconig
/usr/sbin/arp -a
netstat
the beauty of 'sed'
edits a text stream, most common use is find and replace
sed 's/pattern/replace with/g'
get ready for the code!
pod02:~$cat winter2014-20131025.html|grep '^<th class=“ddtitle'|sed 's/^<th class=“ddtitle.*crn_in=…..”>g'|sed 's/<\/a><\/th>g'|sed 's/^\(.*\) - \(…..\) - \(.*\) - \(…\)$/\2:\3-\4:\1/g'
94033:BUSN 1030-001:Business Communications
94017:BUOT 1062-001:Word Processing for Non-Major
94032:CRPL 1010-001:Career Directions
94018:CSST 1031-001:Intro Graphical User Interface
94039:FYEX 1000-001:First Year Experience
94035:GOVT 1010-001:American Federal Government
94001:HLTH 1010-002:BasicLifeSupport-Prof. Rescuer
94007:HIST 1110-001:American History I
94006:HIST 1120-001:American History II
94029:MDNC 0128-001:Cert Nurse Aide/Home Aide
94030:MDNC 0128-071:C.N.A./HHA Clinical
94009:PFIT 1021-001:Jogging (co-ed)
94036:PEPD 1201-001:Philos/Princ/Org of Coaching
94008:PSYC 1101-001:General Psychology I
94013:PSYC 2030-001:Organizational Behavior
94004:PSYC 2207-001:Child Psychology
94003:PSYC 2215-001:Abnormal Psychology
94037:RECC 1007-001:Walking (co-ed)
94034:RECC 1014-001:Cross-Country Skiing (co-ed)
94005:RECC 1015-001:Wilderness Navigation
94021:TECH 1050-001:Orientation to Technology
94015:TECH 1080-001:Manufacturing Methods Lab
94031:WELL 1001-001:Principles of Getting Fit
94002:WELL 1011-001:The Vegetarian Adventure
pretty awesome eh?
editing an html doc on the fly..
Regular Expressions are for text. Wildcards are for files.
sed 's/pattern/replacement/g' find and replace globally
'/^$/d' delete
tr 'a' '7' tr '\n' ' ' tr '#' '\n'
final command from end of class cat winter2014-20131025.html |egrep '(^<th class=“ddtitle)|(^<td class=“dddefault)' | sed 's/</ llll/g'| sed 's/>/ /g' | sed 's/\<l*[^0123456789]*g' | less wizard people dear reader IFS is internal field separator