0

when I run this program it compiles but the second scanf statement just prints and doesn't actually get any variable. However, if I remove the first scan, the program works.

#include <stdio.h>


struct file_struct
{
    FILE *fp;
};

int main(int argc, char** argv)
{
    char open_type;
    printf("Open type [w/a]: ");
    scanf("%c", &open_type);

    struct file_struct new_file;
    new_file.fp = fopen(argv[1], &open_type);

    char text_buffer[128];
    printf("Enter text to add to file:\n\n");
    scanf("%[^\n]s", text_buffer);

    fprintf(new_file.fp, "%s\n", text_buffer);

    return 0;
}
Ankit
  • 1
  • 2

0 Answers0