This code is a simplification from a larger project I'm working on and it sums up the problem in a simple example. I am obtaining input from the user, their name, and then clearing the buffer from any input that did not fit in the C-string. The problem is that After entering the name, the user has to push enter twice for the program to respond, and because I am using getchar() to flush the buffer there is just a clear misunderstanding in the logic of the loop I created. How can I keep the user from entering Enter twice, in otherword what am I missing? Thanks!
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#define BUFFSIZE 10
int main(void)
{ 
    unsigned char name[BUFFSIZE];
    printf("ENTER YOUR NAME: ");
    fgets(name, BUFFSIZE, stdin);
    name[strcspn(name, "\n")] = '\0';
    //flush the input buffer
    int flush;
    while (flush = getchar() != '\n' && flush != EOF);
    printf("Your name is: %s!\n ", name);
    printf("Press enter to continue...");
    getchar();
    return 0;
} 
 
     
     
    