/*
* love_letter_for_Yourname.c
* Compile: gcc love_letter_for_Yourname.c -o love && ./love
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#define RECIPIENT "Yourname"
#define HEART "<3"
#define FOREVER for(;;)
typedef enum {
CALM,
BUTTERFLIES,
STARSTRUCK,
OVERFLOWING
} Feeling;
typedef struct {
const char *vow;
int priority; // higher = more important
} Promise;
static void type_line(const char *s, unsigned delay_ms) {
// A tiny "typewriter" effect (portable-ish)
for (const char *p = s; *p; ++p) {
putchar(*p);
fflush(stdout);
struct timespec ts;
ts.tv_sec = delay_ms / 1000;
ts.tv_nsec = (delay_ms % 1000) * 1000000L;
nanosleep(&ts, NULL);
}
putchar('\n');
}
static void print_border(char c, int n) {
for (int i = 0; i < n; ++i) putchar(c);
putchar('\n');
}
static const char *feeling_to_string(Feeling f) {
switch (f) {
case CALM: return "calm";
case BUTTERFLIES: return "butterflies";
case STARSTRUCK: return "starstruck";
case OVERFLOWING: return "overflowing";
default: return "indescribable";
}
}
static void seal_with_kiss(void) {
printf("\n %s Sealed with a kiss.\n\n", HEART);
}
int main(void) {
const char *dear = RECIPIENT;
Feeling state = OVERFLOWING;
const char *compliments[] = {
"your smile compiles my chaos",
"your laugh links all my loose libraries",
"your presence debugs my day",
"your eyes are the perfect syntax highlighting",
"with you, every segfault turns into a soft restart"
};
const size_t n_compliments = sizeof(compliments)/sizeof(compliments[0]);
Promise vows[] = {
{"I will listen, even between your lines.", 10},
{"I will celebrate your smallest commits.", 8},
{"I will handle your exceptions with care.", 9},
{"I will choose you in every branch.", 10},
{"I will keep our shared state safe.", 9}
};
const size_t n_vows = sizeof(vows)/sizeof(vows[0]);
time_t now = time(NULL);
char when[64];
strftime(when, sizeof when, "%B %d, %Y", localtime(&now));
print_border('=', 56);
printf("Dear %s,\n\n", dear);
type_line("In the language of C—minimal, precise, and brave—", 10);
type_line("I am writing what my heart has been declaring silently:", 10);
printf("\nCurrent feeling: %s (%d/10)\n\n", feeling_to_string(state), 10);
printf("On %s, I linked this program with courage and truth,\n", when);
printf("so it can print what I’ve been running in a loop:\n\n");
// Compliments
for (size_t i = 0; i < n_compliments; ++i) {
printf(" - %s %s\n", compliments[i], HEART);
}
printf("\nPromises (sorted by priority):\n");
// Simple selection sort by priority (descending), because love takes effort.
for (size_t i = 0; i < n_vows; ++i) {
size_t maxj = i;
for (size_t j = i + 1; j < n_vows; ++j) {
if (vows[j].priority > vows[maxj].priority) maxj = j;
}
Promise tmp = vows[i]; vows[i] = vows[maxj]; vows[maxj] = tmp;
printf(" %zu) %s\n", i + 1, vows[i].vow);
}
printf("\nSome truths, in strict ANSI:\n");
printf(" const int distance = 0; // whenever you are near\n");
printf(" volatile long heartbeat = 0;\n");
printf(" FOREVER {\n");
printf(" ++heartbeat; // it’s you\n");
printf(" if (heartbeat < 0) break; // impossible, like loving you less\n");
printf(" }\n\n");
type_line("If love were undefined behavior, I’d still risk it for you.", 10);
type_line("If life tries to optimize us away, we’ll add 'volatile' and stay.", 10);
printf("\nReturn value: ");
printf("love( %s ) == true;\n", dear);
seal_with_kiss();
print_border('=', 56);
printf("P.S. If anyone asks, this letter is portable across all platforms\n");
printf("as long as %s is defined.\n", RECIPIENT);
return 0;
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)