Description:
Description:
Make a simple function called greet that returns the most-famous "hello world!".
Style Points
Sure, this is about as easy as it gets. But how clever can you be to create the most creative hello world you can think of? What is a "hello world" solution you would want to show your friends?
//Write a function `greet` that returns "hello world!"
char *greet(void)
{
char *ptr = "hello world!";
return ptr;
}
another solution
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char *greet()
{
char *code = "++++++++++[>++++++++++>+++++++++++>++++++++++++>+++<<<<-]>++++.---.>--..+++.>>++.<-.<.>-----.<---.<-.>>>+.";
char byteArr[] = {0x00, 0x00, 0x00, 0x00, 0x00};
int pointer = 0;
int outPointer = 0;
char out[14] = "";
int length = (int)strlen(code);
for (int i = 0; i < length; i++)
{
char chr = code[i];
switch (chr)
{
case '>':
pointer++;
break;
case '<':
pointer--;
break;
case '+':
byteArr[pointer]++;
break;
case '-':
byteArr[pointer]--;
break;
case '.':
out[outPointer] = byteArr[pointer];
outPointer++;
break;
case '[':
if (byteArr[pointer] == 0x00)
for (int j = 0; j < length; j++)
if (code[j] == ']')
i = j;
break;
case ']':
if (byteArr[pointer] != 0x00)
for (int j = 0; j < length; j++)
if (code[j] == '[')
i = j;
break;
}
}
char* result = malloc(strlen(out) + 1);
strcpy(result, out);
return result;
} -> ??