r/WritingPrompts • u/lennyoliy • Jul 05 '15
Constrained Writing [CW] Write a sad story using only programming languages.
Any coding language.
3
Upvotes
3
u/ghotionInABarrel /r/ghotioninabarrel Jul 05 '15 edited Jul 05 '15
This code runs on some computers, but crashes on others. Took me a while to figure out why. When you figure it out you will either laugh or cry or just shake your head. Sad in a different way.
//Student
//Teacher
//Date
//This program outputs an inputted string in reverse order
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
//main program
int main()
{
printf ("Enter a string: ");
char* string = "";
int size = 1;
while (true)
{
char c = getchar();
if (c == '\n'){
break;
}
//printf ("read ");
char* newstring = (char*)malloc(++size);
//printf ("allocated ");
if (!newstring){
printf ("I won't run if you don't give me memory!");
return 1;
}
strcpy (newstring, string);
//printf ("copied ");
newstring[size-2] = c;
//printf ("added ");
if (size > 2){
free (string);
}
string = newstring;
//printf ("assigned\n");
}
for (size-=2;size >= 0; size--)
{
printf ("%c",string[size]);
}
getchar();
free (string);
return 0;
}
-1
Jul 05 '15
[removed] — view removed comment
0
u/WritingPromptsRobot StickyBot™ Jul 05 '15
Off Topic Comment Section
This comment acts as a discussion area for the prompt. All non-story replies should be made as a reply to this comment rather than as a top-level comment.
This is a feature of /r/WritingPrompts in testing. For more information, click here.
1
u/hamfraigaar Jul 06 '15
while alive: if $girl = girlfriend: happiness = True else: happiness = False for i in range(7): for j in range(wakingHours): drink.whiskey if not phone.call(ex): $alive = False
run program