I wrote a program that translates a sentence into B1FF language. When i enter a message and hit enter, it doesn't give any output, using a specific piece of code. I can make it work when i write the code in a specific way but i choose to write it in another way, which should be similar. Can you explain why it doesn't work?
This piece of code works for my program and i thought it was similar to the other code:
for(;(message[len] = getchar()) != '\n';) len++;
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define N 50
int main() {
char message[N];
int len=0;
printf("Enter message: ");
/*this is the part that is not working and i have no idea why. I
thought it's similar to the other code i provided*/
do {
message[len] = getchar();
len++;
} while (message[len] != '\n');
for(int i = 0; i < len; i++) {
switch(toupper(message[i])) {
case 'A': putchar('4'); break;
case 'B': putchar('8'); break;
case 'E': putchar('3'); break;
case 'I': putchar('1'); break;
case 'O': putchar('0'); break;
case 'S': putchar('5'); break;
default: putchar(toupper(message[i])); break;
}
}
printf("!!!!!!!!!!");
return 0;
}