Question: I wrote a program that lets the user type words and it saves them to a char array until the user types "\*end".How can i make the program stop when the user presses Ctr+Z instead of typing "\*end"?

Here is the code

```
char text[1000][100];

char end[100] = "*end";
int count =-1;

do
{
    count++;
    scanf("%s",&text[count]);

}while(strcmp(text[count],end)==1);

```

Answer: 
It could be [operating system](https://en.wikipedia.org/wiki/Operating_system) specific. The C11 (or C++14) standard does not know about [terminals](https://en.wikipedia.org/wiki/Computer_terminal) (or [terminal emulators](https://en.wikipedia.org/wiki/Terminal_emulator)) or keyboards, only about [standard output](https://en.wikipedia.org/wiki/Standard_streams), standard input, etc....

On Linux, read about [tty demystified](http://www.linusakesson.net/programming/tty/), [termios(3)](http://man7.org/linux/man-pages/man3/termios.3.html) and consider using some library like [ncurses](https://www.gnu.org/software/ncurses/) or [readline](https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html).

BTW, you'll better use C [dynamic memory allocation](https://en.wikipedia.org/wiki/C_dynamic_memory_allocation) instead of using an array of arrays and you should check the result count of [scanf(3)](http://man7.org/linux/man-pages/man3/scanf.3.html). Look into [strdup](http://man7.org/linux/man-pages/man3/strdup.3.html) & [asprintf](http://man7.org/linux/man-pages/man3/asprintf.3.html).
here is what the `man` page for `scanf()`says about the returned value (not the parameter values)

```
RETURN VALUE
   On success, these functions return the number of input  items  success‐
   fully  matched  and  assigned;  this can be fewer than provided for, or
   even zero, in the event of an early matching failure.

   The value EOF is returned if the end of input is reached before  either
   the  first  successful conversion or a matching failure occurs.  EOF is
   also returned if a read error occurs, in which case the error indicator
   for the stream (see ferror(3)) is set, and errno is set to indicate the
   error.

```

What this boils down to is: 

*ALWAYS check for error conditions returned from system functions.*

suggest changing this: `

```
scanf("%s",&text[count]);

```

to:

always use a MAX CHARACTERS modifier that is one less than the length of the input buffer, to avoid buffer overflow. Such buffer overflow is undefined behavior and can lead to a seg fault event.

```
int retScanf = scanf( "%99s", &text[count] );

switch( retScanf )
{
    case 1:   // normal return
        // handle string input
        // this is where to check for 'end'
        break;

    case EOF: // ctrl-z return
        // user entered <ctrl>-z
        break;

    case 0:   // invalid input return
        // user entered only 'white space' (space, tab, newline)
        break;

    default:  // should always provide for unexpected 'switch case'
        // display error message here
        break;
} // end switch

```