Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8823031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:15:12+00:00 2026-06-14T06:15:12+00:00

I have a program called test.c, and an input file called test.in. I’m trying

  • 0

I have a program called test.c, and an input file called test.in. I’m trying to read two strings from the input file and output them to the console. I’m running Windows 7 but I’m compiling with MinGW using gcc.

This is my file test.c:

#include <stdio.h>
main() {

    FILE *fin = fopen ("test.in", "r");
    char  *one, *two;

    fscanf(fin, "%s %s", one, two);
    printf("%s\n%s", one, two);

    fclose(fin);
    return 0;
}

And this is my file test.in :

ONE
TWO

I go to MinGW, run “gcc -o test.exe test.c”, everything compiles fine, but when I run test.exe, a pop-up comes up and says “test.exe has stopped working. Windows is trying to find a solution to the problem…”

Does anyone know why this is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:15:13+00:00Added an answer on June 14, 2026 at 6:15 am

    fscanf is writing to the uninitialised pointers you pass it. The effects of this are undefined but a crash is likely. You need to allocate your char arrays before calling it:

    #define MAX_LEN (32) /* change this as required */
    char one[MAX_LEN];
    char two[MAX_LEN];
    fscanf(fin, "%s %s", one, two);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse an html output file from a program called mirdeep. I
I have two scripts that are called in one program, the first script creates
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
Every time I test my program, I have to input a bunch of the
I have a test program called ftest. It loads .so files that contain tests
I have a program that needs to read data from a number of sources.
I have got the following code in a file called test.java which is located
I have a toy program that is called Test.class. It accesses a class in
Under Windows, I have used a program called Dependency Walker to examine the libraries
I have made a script that uses a program called Diascope, its a video

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.