i use k&r but generally add spaces in brackets, like:
Code:
if ( a ) {
(TAB STROKE)i1;
(TAB STROKE)i2;
(TAB STROKE)} else {
(DOUBLE TAB STROKE)i3;
(DOUBLE TAB STROKE)i4;
(DOUBLE TAB STROKE)}
(TAB STROKE)}
i ussually use
Code:
if ( a ) i1 else i2;
when using a single instruction. i edit my programs in notepad and prefer to see more of a "condensed" program than less of an "airy" one.
this is an example:
Code:
/*
==============================================================================
=== ===
=== MNR source file - version 0.1 build 046 date 18.08.2005 test-c alpha-3 ===
=== DOS/Windows and UNIX/Linux ===
=== ===
==============================================================================
*/
#include "mnr.h"
//prototypes
char process_com(void);
char test(void);
void process(void);
char cleanup(void);
//global
char *fis, *fos, *com, intr, dash, ign;
FILE *fi, *fo, *dat;
int main(int argc, char *argv[]) {
printf("\n\n\n===============================================================================\n");
printf("=== Welcome to the MNR Monstruous Numbers Reader ===\n");
printf("=== version 0.1 copyright (C) 2005 moonlord ===\n");
printf("=========== FOR TESTING AND EVALUATION ONLY - NOT FOR COMERCIAL USE ===========\n\n");
switch (argc) {
case 1: {
printf("=========== SYNTAX: \"MNR interpretation[switches] file_in file_out\" ===========\n");
printf("=== interpretation - \"a\" or \"b\" or \"c\" - according to whether the output is ===\n");
printf("=== written in American, Britanic or Continental format ===\n");
printf("=== as described in the readme file. ===\n");
printf("=== switches - \"-\" to use dashes between word parts. ===\n");
printf("=== - \"i\" to ignore non-digit characters from file_in; an error is ===\n");
printf("=== generated otherwise. ===\n");
printf("=== * switches are case-sensitive. ===\n");
printf("=== file_in - the number is read from this file. ===\n");
printf("=== file_out - the text is written in this file. ===\n");
printf("===============================================================================\n\n");
return(0);
}
case 2: if (atol(argv[1]) == 443556) {printf(VERSTR); return(0);}
else {printf("ERR01: Syntax error.\n"); return(1);}
case 4: {
com=argv[1]; fis=argv[2]; fos=argv[3];
if(process_com()) {printf("ERR01: Syntax error.\n"); return(1);}
switch(test()) {
case 4: {printf("\nERR04: Error opening data file names.dat.\n"); return(4);}
case 3: {printf("\nERR03: Error opening output file %s.\n", argv[3]); return(3);}
case 2: {printf("\nERR02: Error opening input file %s.\n", argv[2]); return(2);}
case 1: {printf("\nAborted by user.\n"); return(0);}
}
if(count_file()) {printf("\nERR08: Non-digit character encountered.\n"); return(8);}
/**/ reopen_files();
process();
switch(cleanup()) {
case 3: {printf("\nERR07: Error closing data file names.dat.\n"); return(7);}
case 2: {printf("\nERR06: Error closing output file %s.\n", argv[3]); return(6);}
case 1: {printf("\nERR05: Error closing input file %s.\n", argv[2]); return(5);}
}
printf("Done.\n");
return(0);
}
default: {
printf("ERR01: Syntax error.\n");
return(1);
}
}
}
//////////
//
// process_com(): Interpretes command.
// Returns: 0 - success;
// 1 - some syntax error;
//
char process_com(void) {
char *i=com;
switch(com[0]) {
case 'a': case 'b': case 'c': {intr=com[0];break;}
default: return(1);
}
while (*++i) {
switch(*i) {
case '-': {dash=1;break;}
case 'i': {ign=1;break;}
default: return(1);
}
}
return(0);
}
//////////
//
// test(): Tests and opens files (fi,fo,"names.dat").
// Returns: 0 - success;
// 1 - aborted by user;
// 2 - error opening fi (input file);
// 3 - error opening fo (output file);
// 4 - error opening "names.dat";
//
char test(void) {
struct ffblk fot;
char conf;
if (!(findfirst(fos, &fot, 0) == -1)) {
do {
printf("%s already exists. Overwrite? (Y/N)", fos);
conf=toupper(getche());
printf("\n");
} while (conf != 'Y' && conf != 'N');
if (conf == 'N') return(1);
}
if ((fi=fopen(fis, "rt")) == NULL) return(2);
if ((fo=fopen(fos, "wt")) == NULL) return(3);
if ((dat=fopen("names.dat", "rt")) == NULL) return(4);
return(0);
}
//////////
//
// process(): Reads from fi, writes in fo.
// Returns: nothing.
//
void process(void) {
;
}
//////////
//
// cleanup(): Writes buffers and closes files.
// Returns: 0 - success;
// 1 - error closing fi;
// 2 - error closing fo;
// 3 - error closing "names.dat";
//
char cleanup(void) {
if (fclose(fi) == EOF) return(1);
if (fclose(fo) == EOF) return(2);
if (fclose(dat) == EOF) return(3);
return(0);
}
it actually does nothing but is in progress. Will announce when it's ready if you're interested...