User Tools

Site Tools


blog:spring2016:aslater1:start

Anita Slater's Spring 2016 Opus

About Me

Hi, my name's Anita and I love Pink Floyd! This is my second semester in my Computer Science journey and I hope to go on to a larger University to obtain a higher degree. I am an aspiring Software Engineer that enjoys learning new things, long walks on the beach, baking and of course, Pink Floyd.

C/C++ Programming Journal

January 23, 2016

It works! I am so excited that my little program works! I guess it's not that big of a deal, but man, what a feeling!

What really helped me, and what I think I'm going to continue doing, is keeping a notebook of all the commands, what they do, and any epiphanies I have along the way. It really helps to have a physical copy of everything I did during each project. That being said, some of the things that I learned:

  • Indents are essential for having readable code, even though it wasn't super applicable here, I can see how it can/will become an issue in the future.
  • Semi-colons are nice, semi-colons are your friends, love them, embrace them, don't forget them.
  • Pink Floyd is love, Pink Floyd is life just kidding I already knew that

February 1, 2016

Hey,
Hey you
Guess What
My program worked.
I know, I'm shocked too.
There were a couple things that I'm a little confused/happy about:

  • I wrote two different programs, one of them with an unsigned char and one of them with an int. They're exactly the same in every regard except for that part. My int program works for 4 digit numbers while my unsigned char only works with 2 and 3 digits. I think it has to do something with the size, I'll have to check it out.
  • I made my first successful if/then loop. It's pretty much the “hello, world!” as far as they're concerned, but you've got to start somewhere, right!


I've also noticed that as my programs become longer and more complex they're starting to look more and more like abstract art. If you take a couple of steps back and squint your eyes it kind of looks like a children's drawing, but I digress.

**Things to Improve on**

  • Format: If you can't understand it and its typed, you have a problem
  • Commenting:
     //this is a variable 

    isn't really providing any context.

  • Organization: Made very apparent with the loop, I'm not too sure where to put all my variables. For now, I'll just stick them at the top, but I'll need to find out for sure if that's the best place for them.


Ah-Ha Moments

  • %hhu, etc is not an actual value it changes.
  •  fprintf(stdout, "%d %d %d %d", wish,you,were,here);

    each of those values could be different, depending on what the variable are defined as. They're referred to in the order that they appear.

  • Did you know that variables don't have to be a, b, or c?
    Yeah, me too.

February 1, 2016

So, apparently minGW is much more forgiving than the compiler on Lab46 when it comes to format specifiers. Thanks Danny for helping me out, there!
Ah-Ha Moments

  • %d %c is the format specifier for an unsigned char

Edit:

Variable type Format Specifier
char %c
int %d or %i (%u for unsigned)
float %f

February 8, 2016

I'm almost done with the dow0 project, I just have work in those pesky leap years. I think what I'm going to have to do is create another if/then statement and use the % operator. Editing on lab46 is really frustrating with my head-bangingly slow internet, so I'll have to test it out/implement it tomorrow.

February 9, 2016

So the dow0 project got done, there was much rejoicing to be had. I used an “or” operator (The pipe makes a comeback!)

Other than that there's not really much to say. This project was very similar to the last one so must of the stuff was pretty familiar. I have to say that the code, itself, looks a lot neater now (or maybe it doesn't, it looks better to me).

Uhh, I think my commenting has improved.

I'm kind of weary of using vim. Right now its this new scary thing but I should probably start getting more acquainted with it.
Ah-Ha Moments

Careful With That Compiler, Anita
[WRONG] gcc -o something.c name
[WRONG] gcc name -o something.c
[CORRECT] gcc -o name something.c

February 17, 2016

The infamous “multiplying by eleven” project. I heard that this project was difficult due to the three digit numbers and the necessity to do it without loops. I expected to run into a lot of problems so I was pretty surprised the 3-digit part of my program worked without the need of a carry value. The code looked like

     fd = ipt / 100;
     sd = (((ipt - 100) / 10) + fd);
     td = (((ipt - 100) % 10) + sd);
     ld = ((ipt - 100) % 10);
		

fprintf(stdout, “ Answer: %d%d%d%d”,fd,sd,td,ld); </code>


With int values fd,sd,td,and ld representing the first, second, third, and last digits, respectively.

There was no need to send my findings to Old Pink, however, as I was actually inadvertently exploiting the rounding feature of the int type. Which is why I didn't need to carry, since the rounding took care of it for me.

I don't think that satisfies the project requirements, so I'm going to have to redo that part of the code. A cool little unexpected thing, like spotting an obscure Pink Floyd reference.
Ah-Ha Moments

  • int ROUNDS the value (duh)

February 21, 2016

So laziness got the best of me and I decided to leave my code the way it was. I tested it for 4, 5 and 6 digit numbers and it still works, which makes me think I did something wrong.

As for why it works: ¯\_(ツ)_/¯

I'm thinking that is has to do with the rounding, and just how the code is laid out. Another weird thing was my else if statement, that looked like

 else if (99 <= ipt <= 999)

When I entered in numbers larger than 999 it still carried out that section of the code and it still worked. Not sure what was going on there, but I changed it just to make sure.

I haven't been able to successfully replicate the project using loops, so I'm working on getting more familiar with them. Getting better with vim, so that's cool.

February 29, 2016

So yeah, this project was super difficult for me. It was my first time actually using both typecasting and the argc, argv. That being said, I have a better idea of what they both mean. I still have to finish up my prime square root as well as my optimization, so I'll post more code-specific information once I get that done.

Loops are getting more familiar, I didn't think I would ever be able to embrace the for loop, but I'm definitely hooked now. Also its good to implement little “fprintf(stdout,” The value here is %d“,value); to get a snapshot or that the program is actually doing at that point. Many revelations were discovered using that.

March 1, 2016

After I got the logic of the nested loops down, I felt like I was doing pretty good. It's all about incrementing, and knowing exactly what you're incrementing and the effects it has. I broke out of my do while loop habit, and I think I've converted to the for loop camp. Funny enough, the biggest problem I had was getting the time value to display at the end of the output ( \n).

So here, I am, at 11:30 pm, I just test out everything on primerun and I get MISMATCH.

huh, that's weird, I thought I checked like all the prime values. Long story short, I didn't and my output includes 989 (thanks, Eratosthenes) , which is not prime. I mean, I should have known when my opt program was like the easiest thing ever. My other programs also failed, but I'm not sure where, I checked the values up to 1,000 and it matched. Oh well.
What I learned/ Things to Improve On

  1. Testing is good
  2. First incremental value is important
  3. printf(“\n”) for a line break
  4. watch braces

March 6, 2016

 
i = 1973
do
{
    i = i / 5;
    j++;
} while ( i > 0)


i ≠ 1973 anymore.

March 8, 2016

I'm so close to getting the mbe1 project done! Unfortunately, I don't think its going to be before the midnight deadline, so no bonus points for me.
This project wasn't so bad, I think I'm getting arrays more. They're pretty cool, yo.
I thought I was going crazy when I kept seeing a ` in front of my array. I spent way more time than I'd like to admit googling its significance. Turns out it was just left there after the \n, so it printed on the next line.

March 9, 2016

I take it all back, Mercurial.
Learn't

  • Loops evaluate chronologically
  • Make sure to initialize stuff at 0, to make sure it doesn't carry over to the next loop
  • Print out each step of the loop, including if statements
  • Version control source code in the case that you, say, accidentally overwrite it

March 15, 2016

I'm still working on the cos0 project, and so far so good. My math is off, as only one quarter of the circle is visible, but I'll keep tinkering, hopefully I'll get it together.
On an unrelated note: I am super pumped to be learning about file input/output streams. That was pretty much the only thing I did in Java, and I'll attest to the fact that it's the coolest thing ever.

March 17, 2016

Finally got done done with cos0, and just shy of 160 lines. All right! Getting better with loops, although I did have a seemingly superfluous “i++” in my for loop that apparently carried all the other code, as the program wouldn't work without it. Oh, and

 warning: incompatible implicit declaration of built-in function ... 'cos' [enabled by default] 

Means that you forgot to include the math library.

In the prime project ( that I'm trying to forget) I had trouble getting an error message to display to stderr when there weren't enough arguments. It would always seg fault instead of displaying my message. Turns out you can just throw the actual code in an if (argc > whatever) statement and at the end have an else. This way the program still runs (long enough to display the message and exit).
Learn't

  • warning incompatible … → check to make sure you included the header file
  • if statements can save from seg faults
  • Math > trial + error

March 28, 2016

So the sam0 project was a no go, not really proud of that one. I'm going to redo it, just to make sure that I really grasp the idea of multiple functions.

I'm really excited to start working with C++, I'm still a little shaky on the idea of object-oriented languages, but I think I'm on the verge of getting it. My plan is to write make a simple game, Yahtzee, in C, C++ and Java, maybe I'll write it in Python if I'm feeling super ambitious.

Oh yeah, and the next project, I should probably start that too.

April 7, 2016

The cbf project is done, and I kept having a problem with getting the program to stop output once it reaches the end of the file. Because the characters were actually printed in a for loop that was nested inside of the while loop, the while loop would have already run before the for loop could determine if if had reached the end of the file.

I cobbled together a solution involving an array ( which I should have stored the fgetc(whatever) in anyway). The only solution that I could see involved the ability to foresee one character in the future, hence the use of an array. Boom, problem solved, everything else is just green.

April 11, 2016

So I was thinking that I could manage to get through this course without the use of pointers, but unfortunately that is not the case ( which is probably a good thing).

'Neways I'm having a little trouble with function returns, but I think with a little more tinkering I'll get it.

April 12, 2016

Getting really weird output? Try initialing the variable to 0.

April 17, 2016

int i = 0
int proj [ i ];
...
proj[ i ] = something;

WILL SEGFAULT

int i;
int proj[ i ];
...
proj[i] = something;

WILL NOT SEGFAULT ( but is still bad ) i is typically the incremental value ( so you don't really use it for the declaration), if there's anyway you know how much ” stuff you're going to throw in the array, use that instead. Otherwise determine the size and THEN declare it.

April 19, 2016

Holy wall of text, Batman!
Here's the thing: it turns out if you initialize an array with an index of 0, you're going to have a bad time. Which makes since because you're saying that you want to store zero elements. That's why it will crash and burn when you run the program.

In more relevant news, I actually went back through and fixed what may have been the most inefficient program ever. Instead of having main make the array, I just opened the file in each one of my functions (4 times). That was just the beginning, as there were nested loops and a million variables with no point.

I went back through and had main put all the values in the array, and then passed the pointers to the functions. This way I didn't have to open and close the file, and the math turned out to be a lot easier. The code itself is way less complex, and I managed to cut down on more than 40 lines of superfluous garbage. In other words, I think I'm finally starting to embrace pointers. Just in time for the semester to be over!

May 2, 2016

So I've been doing the stuff.

I used some(a lot) switch cases in the project. They took a little to get used to, but they're really handy for comparing a bunch of stuff.

Por Ejemplo:

1
switch (pineapple_pizza)
{
    case 1:
        printf("Is gross");
        break;
    case 2:
        printf("Violates the Geneva Convention");
        break;
    case 3:
        printf("Should not be ingested under any circumstances");
        break;
    case 4:
        printf("Hurts your soul");
        break;
    default:
        printf("Is a literal crime against humanity");
        exit(1);
}

Where the “case #” is referring to the condition you're checking for. Don't forget the :! The use of a 'default' is optional, as well as the break.
Breaks can be omitted if you want the statement to “fall through” and hit multiple conditions.

May 4, 2016

Oh man, I just had all of the breakthroughs.

Turns out, if you're compiling multiple c files, and you simply use

gcc file1.c file2.c file3.c -o combinedfiles

Your functions won't be able to “talk” to each other. That is, you can run the program as many times as you want, but the function will never return anything (at least it wouldn't for me). How do you get around this? Header files! Which, by the way, are where the function prototypes go. Don't put the entire function in there.

So, when using multiple files you can just throw the above into a header file (making sure to include it in main). When you compile the c files functions work!

1
#ifndef HEADERFILE_H_
#define HEADERFILE_H_
 
int stuff(char this, char that);
 
#endif

UNIX/Linux Fundamentals Journal

January 25, 2016

There is no Dark Side of the Moon, really. Matter of fact, its all dark.

So at first I was kind of taken aback by the whole “Linux thing” I'm a pretty faithful Windows user, and I was definitely missing my GUI that first day. However, my Network Fundamentals class that I took last semester kind of prepared me for using a CLI.

What I'm still struggling with is the Mercurial Repository. As of yet, still not a fan. I'm hoping that, like most things, it'll get easier with time.

January 27, 2016

Dear future Anita, When you get this:

 abort: no repository found... (.hg not found) ! 

You tried to use an hg command (pull, push, commit, etc) while you weren't in the proper directory. That's like having your pudding before eating your meat. How can you have any pudding if you don't eat your meat?

Back to directories…

  • Directories are blue. Repositories ≠ Directories
    • Remember: A repository contains many directories
  • Triple-check before you delete directories
    • And then check again
  • When you want to clone to BitBucket use https instead of ssh. this way you don't have to register private/public keys.

February 2, 2016

I'll be honest, I felt pretty cool when I was unscrambling those files and putting them together, like a digital paleontologist. Is it possible that there is a program that randomly tacs and revs files repeatedly to create a kind of encryption? I'll have to look into that. Oh and gzip compression options, I want to check that out, too.

What I Learned/ Ah-Ha Moments

  • This was actually my first time compressing any kind of file. It was neat.
  • -f specifies the file for just about all of the compressing/decompressing commands. When you're getting an error message, you most likely forgot this again
  • Hanging on in quiet desperation is the English way

February 7, 2016

Eureka! There are different levels of compression! Its amazing what you learn when you read the entire manual page! That being said, I'm really liking my decision to keep a notebook detailing the various commands and tips, it came in handy today.
The file tool is pretty cool, before this project I was wondering what was stopping me from giving a file whatever extension I wanted. Like, there's nothing stopping me from putting a

.wishyouwerehere

or

.anotherbrickinthewall

or even

.setthecontrolsfortheheartofthesun

extension. Yes, I tried it. Yes it worked

I don't know if I can handle this power. You win this round, Linux
What I Learned/ Ah-Ha Moments

  • Gzip Breakdown
    • first = fast
    • 9 is the slowest
    • 6 is default
  • Read the whole manual page

February 17, 2016

I almost forgot about this week's entry. I like the Puzzlebox projects, and this one really upped the complexity; it was fun.
In other news, I finally got Ubuntu running on my virtual machine, so I've been playing around with that a little bit. I also tried out the default editor, vi. I had a momentary lapse of reason when I assumed it was vim. Don't think I'll do that again. I have to say, though, I really like Ubuntu, the fact that I don't have to load up putty every time I want to make changes to my repository is nice.

What I Learned/ Ah-Ha Moments

  • sort

I'm still having trouble committing to the local, lab 46 repository, so I'll try to sort that out in the meantime.

February 29, 2016

So
Much
Time
I have spent an inane amount of time on the wpa project. That's okay, though, it was fun. I still have to add a few more pages and submit it, but I'm not too worried about doing that.

Then, magically, I finally figured out how to push and pull to the lab46 repository, it's been a life saver when it comes to not having to edit files online.

March 1, 2016

Who has two thumbs and finally completed their Web Page Adventure?

I just read through it and it is littered with typos and grammatical mistakes. Spellcheck is a lifesaver.

What I Learned

  1. cp -r copies directories!
  2. tar -cf [something.tar] [desired file]
  3. Be careful w/ chmod

March 8, 2016

Much customization very wow.
I may have procrastinated a little bit on this one. Setting the path to home is just $HOME right? Probably should ask…
I'm planning on doing some more reading into the config files and their options, they seem pretty neat.

March 14, 2016

I kept getting an error message when I was converting the rle image to the png format. I think I might have accidentally altered one of the files because when I did the whole thing over again, everything was okay.
Learn't

  • offset: is the distance from the beginning of the file, this is why this number gets “skipped” with dd
  • count: Count this many “blocks”

March 21, 2016

I've been doing some exploration of grep and Wget for that matter. I'm trying to find a way to view the contents of a web page and grep it to just show certain information. I've been trying curl, too which is pretty similar to Wget. I also downloaded lynx, which is probably the coolest browser ever (move over Google Chrome).
I kind of regret not paying as much attention to wget in the customization project, it has some really cool features. I already went back and made some adjustments to my terrible, terrible config file. Cool stuff, yo.

March 28, 2016

I wasn't really aware of what an mbr was, so learning about it was pretty cool. The next project looks a little intimidating and complex.

I'm still getting used to using regular expressions, and I'm working on making some useful shell scripts. For the C class, we used a program called primerun, and it was a really cool shell script. I'm going to attempt to make something similar while fixing up my program, so I'll see how that goes.

April 5, 2016

So, all the stuff I said I would do last week is a no-go. I still want to make a variation of primerun so I'm not going to abandon that pursuit.

Regular expressions are tripping me up a a little bit, but I think that practice will help. I'm using more wildcards, so hopefully it will be the same with Regular Expressions.

Still working on udr2, and I see that time management is a factor of the next project.

April 11, 2016

chmod!

Privilege Denoted By Octal value
read r 4
write w 2
execute x 1

There are three modes:
User Mode: u
Group Mode: g
Other Mode: o
Example:

-rw-rwxr--
with modes being:
  u       g      o
-|rw-|  |rwx  ||r--|
 |4+2|  |4+2+1||4  |
 |6  |  |7    ||4  |

The command to set a file to have these privileges would be

chmod 674 somefile

Set UID, GID & Sticky Bit

Really good information here

This one's a little different. UID/GID are denoted by an upper or lowercase s . Sooo…
SET UID: 4
SET GID: 2
STICKY BIT: 1

Where's the s?
S location Example Octal value
User -rwsrw-rw- 4766
Group -rwx-ws-w- 2732
Both -rws-ws-w- 6732
“S” in u -rwSrwx–x 4671
“S” in g -rwx-wS-w- 2722

The 'Sticky bit' acts in the same way, but is only present in the 'o' field.
Just like the Set GID/ UID, if the 't' is captital, it means that the execute bit is not set. Example:

 u       g      o
-|rws|  |rwS  ||r-t|
 |4+2|  |4+2+1||5  |
 |6  |  |6    ||5  |
7665

or
 u       g      o
-|rws|  |rwS  ||r-T|
 |4+2|  |4+2+1||4  |
 |6  |  |6    ||4  |
7664

April 20, 2016

Oh man, I can't remember the last time I submitted a Unix project on time. Not gonna lie, it feels pretty good. I think this was the first time I made, by myself, an actual complex-ish shell script. It doesn't really look the greatest, it was basically a c program with bash syntax (wait…).
To get the values for the project portion I used an array, and I tried comapring it the way I'm used to, something like

array[index] 
....
array[i] = stuff

but it just got too complicated. So, what I ended up doing instead is this:

array=(`command to get all the values of said array into a space separated list`)

I actually did 2 arrays this way, and incremented through them both with a cool for loop. That being said…:

${arr[*]}  # All of the items in the array
${!arr[*]} # All of the indexes in the array
${#arr[*]} # Number of items in the array
${#arr[0]} # Length of item zero

with more information here http://www.linuxjournal.com/content/bash-arrays I used the ${#array[@]}, which means the number of elements in the array ( I think). I also may have neglected to make the lines shorter than 80 characters because I discovered colors.

Yes.

Escape sequences are pretty cool. Unfortunately my c program now looks dull by comparison.

May 2, 2016

Wow, I feel like its been forever since I've done one of these.
So I've been working on the eoce and its been going 'aight. There's been some more extensive shell scripting going on.

Also if statements.
Lots of if statements, which reminds me:

1
if [ some condition ]; then
    whatever
fi

Is the correct syntax for an if statement, don't have anything touch the brackets(besides ;), either.

If there's some kind of problem where vim doesn't like the “fi” statement, and you're sure that one needs to go there, check to make sure there's a “done” for the appropriate loop.

What if there's MULTIPLE if statements?

1
if [ some condition ]; then
    whatever
elif [ some other condition ]; then
    whatever
elif [ another condition ]; then
    whatever
else      ##Don't need to end on an else, can just use an elif
    whatever
fi

What if you want a COMPOUND if statement, ie if this AND/OR this?

1
if [ some condition ]; then
    whatever
elif [ some condition ] || [ another condition ]; then
    whatever
elif [ some condition ] && [ other condition ]; then
    whatever
fi
blog/spring2016/aslater1/start.txt · Last modified: 2016/01/18 16:05 by 127.0.0.1