Skip to main content

Posts

Showing posts from March, 2017

C: Formatting of pointers

Problems has arose when I was attempting to make a forward declaration for my function which included double pointers in the parameters, which was a function intended to store strings in an array. First, from solving one of my own bug, it is does not work well when an asterisk is being placed after the variable name. Variable declarations after the wrongly formatted pointer declaration would not be valid. Secondly,referencing from: http://parrt.cs.usfca.edu/doc/how-to-read-C-declarations.html The way to read a declaration in C goes like: Start at the variable name (or innermost construct if no identifier is present. Look right without jumping over a right parenthesis; say what you see. Look left again without jumping over a parenthesis; say what you see. Jump out a level of parentheses if any. Look right;say what you see. Look left; say what you see. Continue in this   manner until you say the variable type or return type. S o for the case i

C: IO cautions

This morning I was trying to do some basic file IO with the new learnt file related functions, here are a few cautions to take care of. List of functions : 1)  FILE * fopen(const char* filename , const char* mode ) 2)  int fclose(FILE * stream ) 3)  int fprintf(FILE * stream,  const char* format ,....) 4)  fgets(char * str ,int n , FILE * stream ) 1. Watch the mode of using your file related functions Opening with fopen and mode “ w ”  would always overwrite whatever was in the file beforehand. Therefore, in order to maintain the original content, use the “ r ”  mode for reading only, meaning that no writing can be done to the file, or “ a ”  mode for appending data to the original end of the file. The modes would only support one of reading, appending or writing at a time, where as with a “ + ”  sign added to the end, it would have multiple functions. “ r+ ”  mode would support both reading and writing , similar for “w+”  and “ a+ ” . Constraints for each:

C: A personal way of understanding STACK

Used this to explain stack to my girlfriend and it worked quite well...... The Stack Understanding : To call a function When calling a function, the stack works as below: 1.  Function reached, push arguments(to use) on the stack(inventory), push return address on stack(location of soldier) 2.  Jump to function code(take a ride to blacksmith) 3.  Increment stack pointer to allow space for local variables (pick up materials needed to sharpen sword) 4.  Execute code (sharpen) 5.  Pop local variables and arguments off stack (throw away used materials from the inventory) 6.  Jump to return address (take a ride back to the soldier and give him the sharpened sword) So, we can translate this into a more interesting scenario to understand (at least it worked for me): 1. Mission accepted :            Take the sword from the soldier, sharpen it and take it back to the soldier 2.  Put sword into inventories, record where the soldier is at, take a ride to the blacksmith

Finally! Blog made

After several weeks of procrastinating, finally got this blog settled down. The reason why I really wanted to start a blog was that I was realizing how difficult it was to stay motivated just by keeping a record of progress to myself, and now with a publicly readable blog, its some good pushing factors that would help me to maintain a habit of recording day to day progress, mainly including coding experiences and accompanied with some feelings for life. Feels good to kick off something that I always wanted to do.