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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:13:28+00:00 2026-05-22T03:13:28+00:00

I have a txt file named prob which contains: 6 2 8 3 4

  • 0

I have a txt file named prob which contains:

  6 2 8 3
4   98652
      914
143   789
    1    
527   146
 85      
 1 74   8
7   6 3  

Each line has 9 chars and there are 9 lines. Since I cant make a string array in c, im be using a two dimensional array. Careful running the code, infinite loops are common and it prints weird output. Im also curious as to where does it stop taking in the string? until newline?
expected result for each “save”: 6 2 8 3
or watever the line contained.

#include <stdio.h>
FILE *prob;

main()
{ 
    prob = fopen("prob.txt", "r");

    char grid_values[9][9];
    char save[9];

    int i;
    for (i = 0; (fscanf(prob, "%s", save) != EOF); i++)
    {
        int n;
        for (n = 0; n <= 9; n++)
        {
            grid_values[i][n] = save[n];
            printf("%c", grid_values[i][n]);
        }
    }
    fclose(prob);
}
  • 1 1 Answer
  • 2 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-22T03:13:29+00:00Added an answer on May 22, 2026 at 3:13 am

    if you use fscanf, it will stop after a space delimiter..

    try fgets to do it.. It will read line by line..

    for (i = 0; (fgets(save, sizeof(save), prob) != EOF); i++)
    

    the detail of fgets usage can be found here:
    http://www.cplusplus.com/reference/clibrary/cstdio/fgets/

    –edited–

    here’s the second

    while(!feof(file))
    {
        fgets(s, sizeof(s), file); ......
    }
    

    I think it’ll work well..

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

Sidebar

Related Questions

I have a file named a.txt which looks like this: I'm the first line
Suppose I have a file named abhishek.txt and that contains the following line I
I have a file named 'views.txt' which contains '0'. When the user loads the
I have a text file named num.txt who's only contents is the line 123
I have a file named file.txt which is update by adding lines to it.
I have a zip file named test.zip which contains a directory named invoice. Inside
I am new to unix commands. I have a file named server.txt, which has
I have a file(both .dat and .txt format) which contains numbers(integers) in rows and
i have a file named hello.txt which has the content Hello,there!. I want to
I have a file named file.txt that looks like this: Line 1 Line 2

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.