Skip to content

Added fortune command#24

Open
calebrwalk5 wants to merge 6 commits intoGandelXIV:mainfrom
calebrwalk5:main
Open

Added fortune command#24
calebrwalk5 wants to merge 6 commits intoGandelXIV:mainfrom
calebrwalk5:main

Conversation

@calebrwalk5
Copy link
Copy Markdown

The fortune command is a fortune cookie, it picks random silly quotes


void ksh_fortune() {
const char fortunes[3] = {"Pohl's Law: Nothing is so good that somebody, somewhere, will not hate it.", "You either die a smart fella, or live long enough to become a fart smella", "Everyone asked you about your favorite dinosaur as a kid, now, nobody cares", "Even stock traders want to arrest hatred", "Generically, fiery liquors that produce madness in total abstainers.", "Our remedies oft in ourselves do lie,? Which we ascribe to heaven.", "One of the most conspicuous qualities of a man in security."};
kprintc("\n");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// You are passing a "string" on line 6, 8 and 9 as parameter, but kprintc() only accepts 'char'. If you want to print strings, use kprints(), defined in kernel/io.h.

GandelXIV added 2 commits June 9, 2021 15:36
Added the new $fortune command to ListOfOwnCmds
Copy link
Copy Markdown
Owner

@GandelXIV GandelXIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use display.kprintc() to print chars, and io.kprints to print string.
Also we dont have a random generation library, so no rand() function.
Had to do some tweaks to make it work.

void ksh_fortune() {
const char fortunes[3] = {"Pohl's Law: Nothing is so good that somebody, somewhere, will not hate it.", "You either die a smart fella, or live long enough to become a fart smella", "Everyone asked you about your favorite dinosaur as a kid, now, nobody cares", "Even stock traders want to arrest hatred", "Generically, fiery liquors that produce madness in total abstainers.", "Our remedies oft in ourselves do lie,? Which we ascribe to heaven.", "One of the most conspicuous qualities of a man in security."};
kprintc("\n");
int RandIndex = rand() % sizeof(fortunes);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// We write all libraries from scratch, so no rand() function is available. You will need to write a rand.c and rand.h file in lib/.

Copy link
Copy Markdown
Owner

@GandelXIV GandelXIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebrwalk Should i close this pull request?

const char fortunes[3] = {"Pohl's Law: Nothing is so good that somebody, somewhere, will not hate it.", "You either die a smart fella, or live long enough to become a fart smella", "Everyone asked you about your favorite dinosaur as a kid, now, nobody cares", "Even stock traders want to arrest hatred", "Generically, fiery liquors that produce madness in total abstainers.", "Our remedies oft in ourselves do lie,? Which we ascribe to heaven.", "One of the most conspicuous qualities of a man in security."};
kprintc('\n');
int RandIndex = rand() % sizeof(fortunes);
kprints(arrayNum[RandIndex]);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// What variable is arrayNum? You have not declared it in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants