User Tools

Site Tools


blog:spring2016:aslater1:journal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
blog:spring2016:aslater1:journal [2016/04/21 04:09] – i aslater1blog:spring2016:aslater1:journal [2016/05/05 00:39] (current) – [May 4, 2016] aslater1
Line 151: Line 151:
 Holy wall of text, Batman! \\  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! 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:
 +<code c 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);
 +}
 +</code>
 +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
 +<cli>
 +gcc file1.c file2.c file3.c -o combinedfiles
 +</cli>
 +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!
 +<code c 1>
 +#ifndef HEADERFILE_H_
 +#define HEADERFILE_H_
 +
 +int stuff(char this, char that);
 +
 +#endif
 +</code>
 +
 ======UNIX/Linux Fundamentals Journal====== ======UNIX/Linux Fundamentals Journal======
 ====January 25, 2016==== ====January 25, 2016====
Line 312: Line 355:
 \\ Yes.\\  \\ Yes.\\ 
 \\ Escape sequences are pretty cool. Unfortunately my c program now looks dull by comparison. \\  \\ 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:  
 +<code bash 1> 
 +if [ some condition ]; then 
 +    whatever 
 +fi 
 +</code> 
 +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? 
 +<code bash 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 
 +</code> 
 +What if you want a COMPOUND if statement, ie if this AND/OR this? 
 +<code bash 1> 
 +if [ some condition ]; then 
 +    whatever 
 +elif [ some condition ] || [ another condition ]; then 
 +    whatever 
 +elif [ some condition ] && [ other condition ]; then 
 +    whatever 
 +fi 
 +</code>
blog/spring2016/aslater1/journal.1461211770.txt.gz · Last modified: 2016/04/21 04:09 by aslater1