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 7986831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:57:54+00:00 2026-06-04T11:57:54+00:00

I am pretty new to C and I have got a problem here in

  • 0

I am pretty new to C and I have got a problem here in C:
I want to write a program which reads a txt file and writes the content it a char[50][50].

To read the file I used fopen but I have no idea how to write this into the array. What is a good way to solve this?

  • 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-04T11:57:56+00:00Added an answer on June 4, 2026 at 11:57 am

    EDIT: @BLUEPIXY’s answer is significantly better than this approach.

    @Hidde’s code adapted for this specific example:

    // Include the standard input / output files.
    // We'll need these for opening our file
    #include <stdio.h>
    
    
    int main ()
    {
        // A pointer to point to the memory containing the file data:
        FILE * pFile;
    
        // Open the file itself:
        pFile=fopen ("250.txt","r");
        // Check that we opened the file successfully:
        if (pFile==NULL)
        {
            perror ("Error opening file");
        }
        else
        {
            // The file is open so we can read its contents.
            // Lets just assume its got 50*50=250 chars in.
    
            // Initialise an array to hold our results:
            char array[50][50];
            int row, col;
            for (row = 0; row < 50; row++)
            {
                for (col = 0; col < 50; col++)
                {
                    // Store the next char from our file in our array:
                    array[row][col] = fgetc (pFile);
                }
            }
    
            // Close the file
            fclose (pFile);
    
            // Demonstrate that we've succeeded:
            for (row = 0; row < 50; row++)
            {
                for (col = 0; col < 50; col++)
                {
                    printf("%c", array[row][col]);
                }
                printf("\n");
            }
        }
        // Return 0 indictaes success
        return 0;
    }
    

    Really there should be some code to check that the input file meets your expectations, otherwise strange things may happen.

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

Sidebar

Related Questions

I have got a List<Problem> which I want to export to a column based
I'm pretty new to PHP and have a String which contains an HTML page.
I'm pretty new to iPhone development and have struggled to find what I consider
I am pretty new at CSS but have been learning, doing my moms small
I am pretty new to this iPhone dev thing but so far I have
I am pretty new to Haskell but I feel like I have a decent
I am pretty new to the whole Java and OSGi world and I have
I'm pretty new to SQL. I have a database with records based on road/milepoints.
So I am pretty new to JSP. I have tried this a few ways.
I'm pretty new to NHibernate. I have working many to many mappings. they look

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.