Failure to follow the guidelines may

CS 262 Program Style Guide All programs (labs and programming assignments) submitted to Blackboard must adhere to the following guidelines. Failure to follow the guidelines may result in a loss of points on the assignment. No Global Variables Allowed Global constants are ok: const int myConst = 100; Functions A function should generally return only at the end of that function. Avoid writing functions that contain multiple return statements, especially if it is difficult to track return statements within the body of the function. Each time a new block or block-like construct is opened, the indent increases by 2 to 4 spaces (be consistent). When the block ends, the indent returns to the previous indent level. The indent level applies to both code and comments throughout the block. (You may find the Unix indent program found on Zeus helpful. Type man indent) Each statement is followed by a line break (i.e. one statement per line). Braces are used with if, else, for, do and while statements, even when the body is empty or contains only a single statement. Functions (including the main() function) should rarely contain more than 15-20 lines of code. This number is variable, of course. If you find that your function performs several different operations, then it should be broken up into smaller functions, where each function performs a single operation. If you find that you have more than two or three levels of indentation in a function, then it is likely that you should be breaking that code up into smaller functions. Reading Input from stdin Never use scanf() to read data from standard input. Instead, always use a combination of fgets()/sscanf() to read input. Example: char Buffer[100]; int myInt = 0; printf(Enter an integer -> ); fgets(Buffer, 100, stdin); sscanf(Buffer, %d, &myInt); printf(The integer you entered is %dn, myInt); #include files Never #include a *.c file When a separate header file is created for a program, it will contain the prototypes for all functions that are in the corresponding *.c file. Header files must contain macro guards malloc() Always check the return value of a call to malloc() For every call to malloc(), there is a corresponding call to free(). fopen() Always check the return value of a call to fopen() For every fopen() call, there is a corresponding call to fclose(). Filenames Filenames should be in the following format: __.c (or .h) Where is the specific file (labX, projectY, etc.) is the students GMU email ID (username on zeus) is the specific LAB section (not lecture section) where the student is enrolled Arrays Never use a variable length array: int size; printf(Enter size of array: ); fscanf(%d, &size); int myArray[size]; // NEVER DO THIS!!!

Pssst…We can write an original essay just for you.

Any essay type. Any subject. We will even overcome a 6 hour deadline.

<< SAVE15 >>

Place your first order with code to get 15% discount right away!

Impressive sample results