"B1ff filter" reads and returns message This is a programming exercise from chapter 8 of a C learning book by K N King. The program should prompt a user for a message, and return it after translating it to B1ff speak. e.g A->4, b->8 etc

The program works as asked in the exercise, however how can I create a more efficient declaration of the message[] array? Currently it is initialized to size N which is defined as 100 (large enough for most messages), instead of the size of the message from the user.

#include &lt;stdbool.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

#define N 100

int main(int argc, const char * argv[]) {


    //Initialize
    char message[N] = {' '};
    char ch;
    int i = 0, j = 0, k= 0;


    //Prompt user for message
    printf("Enter a message: ");
    //Get message and put each character into an array
    while((ch = getchar()) != '\n'){
        ch = toupper(ch);
        message[i] = ch;
        i++;
    }
  //Print the B1ff speak converting characters
    printf("In B1FF-speak: ");
    for(k = 0; k&lt;i; k++){
        switch(message[k]){
            case 's':
                printf("5");
                break;
            case 'O':
                printf("0");
                break;
            case 'I':
                printf("1");
                break;
            case 'E':
                printf("3");
                break;
            case 'B':
                printf("8");
                break;
            case 'A':
                printf("4");
                break;
            default:
                printf("%c", message[k]);
                break;
        }
    }

    //Print 10 or so exclamation marks and be a citizen
    printf("!!!!!!!!!!!!!!\n");
    return 0;
}
Unused: we don't use j, and we don't need to include &lt;stdbool.h&gt;, &lt;stdlib.h&gt; or &lt;time.h&gt;.
We have two loops - one that reads input into message[] and one that converts and outputs the content of message[].  We can avoid the storage by combining the two loops into one:
while ((ch = getchar()) != '\n') {
    ch = toupper(ch);

    switch (ch) {
        /* ... */
    }

There's a couple of fixes needed above.  Firstly, we need to check that ch is not EOF, or we'll loop indefinitely if the input stream is closed before the first newline.  ch needs to be an int value here, as the distinction between a character and end-of-file is lost when we narrow to char.
Secondly, ch holds values of a (possibly signed) char, but toupper() (like all the &lt;ctype.h&gt; functions) works on an int representation of unsigned char value.  Fixing those gives us:
int ch;
while ((ch = getchar()) != '\n' &amp;&amp; ch != EOF) {
    ch = toupper((unsigned char)ch);


Instead of the switch, we might consider a table-driven approach.  That would work something like this:
char conversions[UCHAR_MAX];
/* identity mapping for most chars */
for (unsigned i = 0;  i &lt; sizeof conversions;  ++i) {
    conversions[i] = (char)i;
}
/* exceptions */
conversions['S'] = '5';
conversions['O'] = '0';
conversions['I'] = '1';
conversions['E'] = '3';
conversions['B'] = '8';
conversions['A'] = '4';


int ch;
while ((ch = getchar()) != '\n' &amp;&amp; ch != EOF) {
    putchar(conversions[toupper(ch)]);
}


Finally, puts() is simpler than printf() for simple strings ending in newline, and we don't need to return 0 from main().

Modified code
#include &lt;ctype.h&gt;
#include &lt;limits.h&gt;
#include &lt;stdio.h&gt;

int main(void)
{
    char conversions[UCHAR_MAX];
    /* identity mapping for most chars */
    for (unsigned i = 0;  i &lt; sizeof conversions;  ++i) {
        conversions[i] = (char)i;
    }
    /* exceptions */
    conversions['S'] = '5';
    conversions['O'] = '0';
    conversions['I'] = '1';
    conversions['E'] = '3';
    conversions['B'] = '8';
    conversions['A'] = '4';


    printf(&quot;Enter a message: &quot;);

    int ch;
    while ((ch = getchar()) != '\n' &amp;&amp; ch != EOF) {
        putchar(conversions[toupper(ch)]);
    }

    // Finish the sentence
    puts(&quot;!!!!!!!!!!!!!!&quot;);
}