Useful old C code of mine. Might be useful for reference.

Posted: May 11, 2012. At: 7:57 PM. This was 6 years ago. Post ID: 3795
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

This is a nice little program I wrote ages ago.

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/********************************************************************
* Description:
* Author:  
* Created at: Wed Jan 19 13:06:21 EST 2011
* Computer: myhost
* System: Linux 2.6.33-ARCH on x86_64
*
* Copyright (c) 2011   All rights reserved.
*
********************************************************************/

#include 
#include 

#define format "At this time: %H:%M:%S"
#define text "OP is a Troll."

int lineofstars (void) {
	int x = 0;
	while (x < 64) {
		printf("*");
		x++;
		if (x == 31) {
			printf("<|>");
		} else if (x == 64) {
			printf("\n-\n");
		}
	}
	return 0;
}

int main (int argc, char** argv) {

	lineofstars();

	char *File;
	char String[60];
	struct tm *ptr;
	time_t tm;
	char length[60];

	tm = time(NULL);
	ptr = localtime(&tm);
	strftime(length, 100, format, ptr);

	File = "log.txt";
	snprintf(String, 100, "%s, %s\n", length, text);

	FILE *f;
	f = fopen (File, "a+");

	if (!f) {
		printf("Sorry, I cannot open the file %s.\n", File);
		return 0;
	}

	fprintf(f, String);

	fflush(stdout);
	fclose(f);

	return 0;
}

No comments have been made. Use this form to start the conversation :)

Leave a Reply