'user input with char array and fgets, output with write system call?

This code, for some reason, is giving me a corrupt final character- both writing to file and printf do not have the last character entered

#include <stdio.h>
#include <stdlib.h>
#include "ssem.h"

int main(){
    int sem_WF, sem_WF_key = 123456, fileID, callStatus;
    char user_input[21];
    
    /*sem_WF = sem_open(sem_WF_key);*/

    fileID = creat ("data", 384);
    if (fileID<0) {printf("Error with creat"); return 0;}

    printf("Enter up to 20 characters: ");
    
    fgets(user_input, 20, stdin);
    printf("%s\n", user_input);

    callStatus = write(fileID, user_input, 20);
    if (callStatus<0) {printf("error with write"); return 0;}

    callStatus = close(fileID);
    if (callStatus<0) {printf("error with close"); return 0;}

    return 0;
}


Solution 1:[1]

The Play Store has a page explaining the different use-cases allowed and restricted for the SMS permission: https://support.google.com/googleplay/android-developer/answer/10208820

The one you're describing is not a valid use-case. However it is mentioned in the alternatives to common use-cases - "SMS OTP & account verification". The SMS Retriever API seems to be what you need which doesn't require the READ_SMS permission.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1