Question: getc (stdin) reads keyboard input to integers, but what if I want to read keyboard input to character strings?

```
#include "stdafx.h"
#include "string.h"
#include "stdio.h"
void CharReadWrite(FILE *fin);
FILE *fptr2;

int _tmain(int argc, _TCHAR* argv[])
{   

    char alpha= getc(stdin);
    char filename=alpha;
    if (fopen_s( &fptr2, filename, "r" ) != 0 )
      printf( "File stream %s was not opened\n", filename );
    else
     printf( "The file %s was opened\n", filename );
   CharReadWrite(fptr2);
   fclose(fptr2);
   return 0;
}
void CharReadWrite(FILE *fin){
    int c;
    while ((c=fgetc(fin)) !=EOF) {
        putchar(c);}
}

```

Answer: 
Continuing with the theme of getc you can use `fgets` to read a line of input into a character buffer.

E.g.

```
char buffer[1024];
char *line = fgets(buffer, sizeof(buffer), stdin);
if( !line ) {
  if( feof(stdin) ) {
      printf("end of file\n");
  } else if( ferror(stdin) ) {
      printf("An error occurerd\n");
      exit(0);
  }
} else {
  printf("You entered: %s", line);
}

```

Note that ryansstack's answer is a much better, easier and safer solution given you are using C++.
<http://www.cplusplus.com/reference/iostream/istream/getline/>
Ta da!