User Tools

Site Tools


opus:spring2015:ssmit133:journal

C/C++ Programming Journal

01/22/2015

For me, this class is my lab. Yesterday Joe lectured about bitbucket and some insanity called “scrum”… So I decided to read on my own in the textbook he suggested for us to buy if “we learn better that way”. I learned how to write a basic hello world script in C format and compile it. After I complied it,I learned that compling it turned it into an executable program which surprised me considering in unix we had to chmod it. Also, the end of lines should also have a \n if you want it to display a new line at the end. if you hit the space instead, it will produce an error when complied.

02/04/2015

Today in Joe's C class we.. did something. He has a new flow chart style presentation doing something.. But on the other hand I independently went through the beginning sections of the book about “character input and output” and learned a decent foundation that will help hand in the mms0(mental math by 5) project that is due today. There are so many differences in writing scripts in C rather bash. But I'm slowing beginning to think that C is possibly easier then bash. For example,

to call a variable its: c = getchar() then putchar©

02/05/2015

rather then dealing with input and the $variable since it is so easy to mix up variables when all of them are only labeled with $.

And then in C you must “int/float/short ect” each variable in the beginning to use them in the script. I find this to be a great requirement since it could be easy to forget what the variable is called exactly or how many your using in the script.

The comments are different so rather # in bash its /* text */ like in html I learned in web design. In bash, I did not need an escape character to end a line for the program to know. Then time we need things like \n for new line \t for tab \b for backspace \“ for double quote
for backslash

I learned how to deal with different types of number inputs (floating points ect) I learned that for and while loops can be similar but for loops are better for logically related single statements.

02/05.5/2015

Im not sure how I messed up my opus entries. Today we disccused if statements and introduced the next mental math program due next week. Today in class we are writing a script that wants us to guess a number.

We also lectured about the technical rules of if statements inside of C. and that you can only have one else statement but you can have multiple else if's. also the else statement MUST be last. the command “srand” was introduced. we created a basic guessing program (version 1) that wants us to guess a number 1-10.

02/11/2015

Today in C class, we were shown examples of how arrays worked. Which how we skipped to that is beyond me, apparently it was picked up examples from Monday's class which only a hand full of students went to. A lot of people stayed home due to the bad travel conditions.

I do not feel like I am up to that point so I disregarded his array examples in class and worked on my current bge3(aka magic number game v.3 with cheat mode&hot/cold hints). I finally realized what I was doing wrong when it came to the hot and cold hints, but now i am stuck on the “cheat mode” bit. My logic was to have it that if say “11” were entered: Cheat mode will kick in and show the answer but then I realized this logic would not work since we are not allowed to use loops. Despite that rule of the program, every time I have it printing out what should be the computers pick- it shows a 5+ digit number rather just a one digit number. Which is weird to me since i do not understand where the rest of these numbers are coming from. It is also seeing the higher number as a hot hint so it double displays the bad cheat mode number plus “your number is too high!”. Which is probably wrong for being “correct” but technically both statements are true.

today in C lab we we did our magic number game to include loops, else if. and then we learned all about the basics of arrays, multi demensional arrays. then we wrote a program using loops/arrays which i submitted to bitbucket

02/12/2015

Today in lab I was able to get through my the mbe0(mental math by eleven) project. It was even more exciting that it was submitted on time.

With this projects practice, I especially learned and put to use the && logical operator which came in handy since there isn't a practical way around it. I also did my first nested if statement to handle “carrying” once and twice for the three digit and four digit result numbers.I also learned the hard way that you need a comma after the qoute ending a printf that has ”%d“ or it will error. Also it was important to set carry to 0 so the math will be done correctly. Today we are also getting introduced to mbe1 where now we are doing a up to 8 digit number by 11. After using the nested loops in the previous project with the up to 3 digits, a up to 8 digit would not be too bad since now I can probably just find a way to loop everything finally. The project information also wants us to use arrays and loops together. I have never used arrays, Joe tried to show us it in class I think, but he kept referring back to the C standard and he just lost me this week in class. It wasnt even on his to do list in class, marcus asked him to teach it in order to do a hex editor(i believe that was his intent) project for the class backlog.

02/13/2015

Today in joe's class we had our daily scrum meeting. In our group we talked about where we were in the aspects of the hex editor and what we wanted to try to do. Then today Joe introduced the hex editor project and the logic of converting numbers back and forth. Everyone seemed confused. He pulled up c program with an example array of hex numbers to use as examples.. He also suggested another project we should consider is a binary calculator. He offered to check anyone's code who might email him over break for both projects. I do not feel confident I will finish either and I don't feel like I've had enough actual coding practice to tackle such a big project yet.

02/23/2015

Today in Joe's class we talking about the and, or, not operators for the logic library and wrote out some sample code on the board.

char andd(char op1, char op2) { if (op1==p && op2==p){ } char result = o if(op1==p) { if(op2==p) { result = p; } } return result;

03/05/2015

Today in C lab we opened 2 terminals. One ran the “grabit” script Matt wrote then the other “wemux” on the other that opened up a cool seemingly game with a list of users connected to the terminal. But it isnt a game :(. We are all sharing the same terminal. On our screens we can now see whatever anyone is typing or adjusting on there screens in “live action”. We are now seeing a program Matt wrote that deals with debugging programs since everyone is starting to have that problem since our scripts are getting much more complex. We are looking at issues of returning pointer data from a function. We can express arrays with bracket syntax and also pointer () syntax. We are using stringlenght function here with Joe would be surprized at.

Joe told us about malloc. Which is a great tool. You pass it a number of bytes and it ask the OS if it can have those number of contunious bytes to use for your script, if not it will return a null. sizeof returns a number of the size of bytes a piece of data occupies.

This is important to make this code portable so the code can be used on other systems(“it will always do the right thing”).The larger of the lenght of an arguement, the larger the amount of memory we request will be.

(char *) is a type cast. its used for data in a certain format like an interger that can easily fit into a char but it wont let you- you cast it in with the char. It temp changes the types to merge into the different format. Malloc returns raw memory to you.thats why we see (char *) malloc (sizeof ..) in this order.

if you dont want an infidnite loop, you need to change “i” somewhere. either in the for( ) or inside of the loop itself {}.

char *data; =equals= char data[]; however depends on how you declare the array, the complier will get angry at which way you do these steps. the [] method is “lying to yourself and hiding from the truth”.

if you treat something as a pointer, return it as a point so: return(data); (pointer)

look up : man strlen man strnlen

we learned about fputc prints a single character to the screen. There is alot more over head to a fprintf function rather the fputc. Its meant to waste less bytes. double qoutes imply “a\0” single qoute like 'a' is the literal single character.

Our script we were working on in class in the “wemux” also errored out at the end because the error messages basically read we did not include all of the approipate header files. We needed <stdlib.h> then now the next error we are seeing is an logical error. Since it is now infidnitely looping. Now to debug on on our own it is suggested to place things like printf's to see where the loop is getting hung up. So now we are inserting “printf(“a,b,c,d..\n”) between certain parts to see where we got lost. We did not get to “c” which ended up being our for loop.

Another debugging tool is the acutal debugger. we should not rely completely on the debugger because it is better that we identify the program. First to use it: we need to add a -g to our gcc compile command. its suggested: gcc -g -o name name.c Compling with the bug support, it added a bunch of bytes to the size of our program. To use the debugger, you use a command called “gdb ./name” it gives you a wall of text about crap. then you can type in it appears as: (gdb) If we had a segfault error, it would find it excatly for us.

so now we type: list. and if we hit enter it will repeat the last command.

to pay close attention: set a break point. so (gdb).. break allthezeros break 28 break main run things (this is us talkign tot he debugger)

we have not run line 14 so it provides us and its up to us to keep going. so we did “print argc” and it tells us excatly what the argc value is.

step: run one instuction then stop next: runs the entire function at once but keeps us where we are.

its a bad idea to single step into a printf function. very bad.

there is a command called “contunie” that resumes normal excecution. This is the point of debugging: setting up break points you care about investaging. then let the program run like normal until the end or the next break point.

a pointer that has the value of 0x0 it means it is NULL (like saying pointer equals 0 but that will be a problem in pointers so that is why we set it to NULL)

you can set an automatic print (or a display point) so when we say “display i”. it prints out what i is forming.

i++ this increments i after ++i increments i before The double assignment is messing with it.

This is why we are seeing an infitnite loop in this program.

“This is a very helpful and valuable tool especially when code gets more complex. Especially since what we imagine is going on with the code, the computer might be thinking something else. So we need to be able to identify and fix the problem(especially independantly)”

Also, When I was listening to other students talk, I also learned about an awesome site called vim-adventures.com that basically teaches you all about the basic commands in VI text editior but in a game form. It's pretty neat but I do look down on the fact they allow you to still use the arrow keys. I feel as if to make the game live up to its name, they should force you to keep using the “hjkl” the entire time. It's pretty fun because it makes the commands “fun” by using them to help you move your character around the levels. However, I refuse to pay 25$ for a lisence to be able to save the game. I might of considered it if it were less then 5$. but 25$ will fill up my gas tank for a week; I'm not trying to break the bank.

03/11/2015

Today in class we discussed the different projects due again and the Assembler project was explained. Basically for the program we need to write a script that takes ASCII input tags and spits out the data in “machine language” aka 101010001110010101010101 etc.

Then the new Random number generator: we need to make the generator actually change the number every time with a seed. we use the rand function. its actually called a pseudo-random number –> its a sequence of random numbers. Whats relative is the value of one number relative to the number next to it, which ends up actually making it “random”. We want to do this quickly and efficiently as possible. Most rand functions built into langues use the idea of Linear Congruence. TIP: write a program to check if the number is prime then pull it into this random number generator script. You'll never find 2 prime numbers that are different by 1. so it makes a number guess a lot better.

03/12/2015

Today in C lab we are going to learn about fopen first we ran grabit to get stuff.dat we are going to use this file for another program. we are writing a program to decode this and find a special key to unlock to see what the data acutally is. we need to decode it to the deminsions of this image (that it acutally is) Read the data and print them out by 59 x 23 . 59 characters on one line at a time. we are now using a file pointer, then we need to assiocate it to fopen if we did not open the “stuff.dat” right, it would return NULL. Now we need to read in a hex character from the file and print out its ascii equalivelent. we used fscanf then to read in each single character. now we are printing out that ascii equivulent. we use fprintf to print the fist character.now we are putting this in a complete loop.

03/17/2015

Today in my C projects I successfully fixed all of the math in my mbe1 project. And I now understood of the concept of switching between intergers and strings. And how that could easily effect the intended outcome of the “math” part to the project

03/18/2015

in C class with Joe, we looked at a url's source code and we were explained the tags and data stored. For the HTML processing project

version 1: Store only characters not between < >

version 2: Dont store only whitespace between > <

version 3: dont store characters between ”< script” and </script“ inclusive

version 4: dont store characters that are between ”<body“ and ”</body“ inclusive

version 5: create a library for this code we just wrote

03/19/2015

put this before main aka global or if it is going to be used only in main it can go there struct candy { char name[80]; char good; char wrapped; char soft; char sweet; int qty; }; typedef struct candy Candy; sometimes its good to make Capital Variables only for struct to perserve sanity later. these are the same thing- both declare the instance of the struct struct candy mycandy; this is declaring the mycandy variable since you need to identify which struct you want to create off of.

int thing[18];

strcat(mycandy.name, “Necco waffers”); its a function.the ”.“ lets you acess ONE of the things inside mycandy.name[2] mycandy.good=1; assiging a 1 to the memory “good”

printf(“good is %hhd\n”,mycandy.good); its the same as printing out as any other variable candy*t; t is a structure pointer t=&mycandy;

t→qty=50; this is the proper structure pointer for structs use a dot if it is not a pointer

structs allocate space union stuff { int a; float b; }; the union is like a struct with thigs inside in this union will only allocate the amount of space of the largest thing and make everything SHARE space. this is useful if you want to use pieces of data to save memory

HPC Fundamentals Journal

01/22/2015

today we learned how to bypass a bios password.

I already knew about the bios menu somewhat from previous A+ courses but the new thing I learned was about the “jumper”. The jumper is the small removable blue chip.The jumper basically purposely short circuits the motherboard to for a bios password to be required. So taking it out and rebooting the sytem then putting it back and rebooting again resulted in the preloaded/old password to be reset. Then after navigating through bios settings, I learned how to partition the hard drive. I had a 160gb hard drive so I divided it out to be 80gb free space for later in the semester, 8gb swap space, and then 72gb for debbie. Then I started the install and proceeded to argue with kyle about the history of dogs and betta fish care. Later I finished setting up the computer station and set up lab46 again.

01/27/2015

Today we are starting to atleast read linuxfromscratch.org . After we feel confident enough we are going to pick starting off with “system d” or the “pure version”. It's said that system D isn't too popular by many because of the way it loads the system and functions.

01/29/2015

Today the class and Mr.Haas helped me fixed my dual monitor problem. It turned out it was as simple as not putting the one word “Display” in qoutes. Which is really annoying but it was a good learning experience to remember that some operating systems just require that technicality. Now I am going to start the project since on one screen I have terminal constantly going and on the other following directions.

02/03/2015

So today I logged back into to my station to continue my project and realized, I cant contunie until I get back into my original path I was using. It turns out I need to remount again so I need to do this process in terminal daily until I am done with the project. mount /dev/sda3 /mnt/lfs LFS=/mnt/lfs cd /mnt/lfs

then switch into LFS account with su - lfs

02/05/2015

Today in HPC I kept repeatedly running into errors in the GCC pass 2 for the linux from scratch project. And I also cleared up a lot of the confusion I had with the first C program mental math by 5's (mms0). Early on we though we were warned about errors like this happening frequently. It turns out I was not matching up the %d%d's to the variables the right way in order for the answer to display correctly. I did finally get the program working properly and commited to bitbucket for joe to see too.

02/10/2015

Everything is broken. Linux from scratch is challenging. i keep repeatedly getting errors in make.

I had to possibly go back to Glibc-2.20's make section since GCC-4.9.1 - Pass 2's make failed with a missing libdev things..

im seeing:

collect2: error: ld returned 1 exit status
make[2]: *** [/mnt/lfs/sources/glibc-build/sunrpc/cross-rpcgen] Error 1
make[2]: Leaving directory `/mnt/lfs/sources/glibc-2.20/sunrpc'
make[1]: *** [sunrpc/others] Error 2
make[1]: Leaving directory `/mnt/lfs/sources/glibc-2.20'
make: *** [all] Error 2 

errors on Glibc-2.20's make.

03/03/2015

Today we talked about moving our computer over to the routers in the lab. We talked all about what subnetting was,dhcp, mac addresses, how the liar is set up, what offbyone.lan/projects.lan/lair.lan was, the netstat -nr command, why it is 255.255.255.248, how to handle and edit the files in router/var/named/master.

I was personally assigned/chose the 48-55 range 255.255.255.248 submask - 10.80.9.55

03/05/2015

Today in HPC I fixed the old problems I had in Linux from Scratch project. Also, I updated my BIOS. But I had to do it borrow another student's flash drive and download my computer's updated version from the dell site. I use a Optiplex 745 and his USB had the update for a Optiplex 755. Then I rebooted my computer with the USB and let the update take place. From there I went on to research what my mac address was then I went over adding my system to the projects server with Matt Hass. I had the “48-55” section which made my network IP: 10.80.9.48, my broadcast IP: 10.80.9.55, my router's IP: 10.80.9.49. I then edited all the files like /var/named/master etc to add myself. Then ran confupdate all so the changes will push. For my Linux from Scratch I am now on the 6.3 Package Management chapter.

opus/spring2015/ssmit133/journal.txt · Last modified: 2015/03/19 16:09 by ssmit133