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

  • SEARCH
  • Home
  • 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 7688815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:00:44+00:00 2026-05-31T20:00:44+00:00

Is possible to read from a txt file in loop like this? files names:

  • 0

Is possible to read from a txt file in loop like this?
files names: input_1, input_2, …, input_20, the “k” in “input_k” is ment as variable.

for ( int k=0; k<20; k++ ){
    fr = fopen("input_k", "r"){
        for ( int i=0; i<width; i++ ){
            for ( int j=0; i<height; i++ ){
                fscanf( fr, "%d", &input_k[i*width+j] );
            }  
        }
    }
    fclose(fw);
}
  • 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-05-31T20:00:46+00:00Added an answer on May 31, 2026 at 8:00 pm

    I think something like this is what you are aiming for, which will work with C89, C99, and beyond:

    int k;
    int input[20][WIDTH][HEIGHT];  // where WIDTH and HEIGHT are 
                                   // compile-time constants
    ...
    for ( k=0; k<20; k++ )
    {   
      char fname[10];
      sprintf(fname, "input_%d", k);
      FILE *fr = fopen(fname, "r");
      if (fr)
      {     
        int i;    
        for (i=0; i<WIDTH; i++ )
        {  
          int j;           
          for (j=0; j<HEIGHT; j++ )
          {                 
            fscanf( fr, "%d", &input[k][i][j] );             
          }           
        }
        fclose(fr);     
      } 
    }
    

    However, I’m making a number of assumptions about your intentions here, so this may not be what you really want.

    EDIT

    Fixed some typos, got rid of width and height variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that its possible to read from a .txt file and then convert
The usual way to read a file in C++ is this one: std::ifstream file(file.txt,
I'm looking for a way to read from an external text file map.txt (allocated
Is it possible to have a Windows Form read it's properties from a file,
This program is supposed to open a txt file, record the answers from two
Possible Duplicates: C++ Read Lines from File File based Configuration handling in C (
Is it possible to read WPF ResourceDictionaries from WinForms? If yes, how?
Is it practical / possible to use serialization to read data from an RSS
Is it possible through javascript to read the number from the iphone. Lets say
From what I've read about Windsor/Microkernel it is in theory possible to do everything

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.