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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:50:03+00:00 2026-06-15T09:50:03+00:00

In this program I have a file called ‘accounts.dat’ and in this file there

  • 0

In this program I have a file called ‘accounts.dat’ and in this file there are some lines of data like

1000:first
2000:second
3000:third

But when I tried to fscanf the data values into my arrays in my program I get:

0:$ s·°Ïÿ¿
1:t·¨BuÞZ·
-1217025816:s·0s·É¥s·hp[·4£s·

As the values scanned, or at least thats what it’s showing.

My function to scan the values is:

void read (int accounts[MAX], char debcred[MAX], double amount[MAX], char accname[][MAXSTRING], char transname[][MAXSTRING], int *i) {

FILE *fp1 = NULL;
//FILE *fp2 = NULL;

fp1 = fopen("accounts.dat", "r");
//fp2 = fopen("transactions.dat", "r");

int h = 0;



if (fp1 != NULL) // READING THE FILE
{
    while(fscanf(fp1, "%d", &accounts[h]) != EOF)
    {

            fgetc(fp1);
            fscanf(fp1, "%30[^\n]", &accname[h]);
            h++;

            printf("%d:%s\n", accounts[h], accname[h]);

    }

    fclose(fp1);
}
else
    printf ("Failed to open file\n");

}

And how I call my read function in my main is:

read(accounts, debcred, amount, accname, transname, &i);

And my declarations in my main function is:

int accounts[MAX], accounts2[MAX], account;
char debcred[MAX], accname[MAX][MAXSTRING], transname[MAX][MAXSTRING];
double amount[MAX];

Can anyone figure out what my problem is? Why aren’t the data lines in my file being scanned into my arrays in my program properly?

  • 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-15T09:50:04+00:00Added an answer on June 15, 2026 at 9:50 am
    fscanf(fp1, "%30[^\n]", &accname[h]);
    h++;
    printf("%d:%s\n", accounts[h], accname[h]);
    

    Try incrementing h after you print.

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

Sidebar

Related Questions

I have a large file called fulldataset . I would like to write lines
I have this servlet program and an external .jar file (written by someone else)
I have a text file exported from a Foxpro (Dos-based) program, but this text
I have a program that generates a .shp file, and exports this as a
My situation is simple. I have this in my program: File folder = new
I have a file called !input.txt containing multiple lines, each line is a random
I have a file called VAR.bat that sets variables: SET VARa=C:\Program Files SET VARb=C:\Program
I have a problem when I compile my program. It is written like this:
I'm trying to work this out. In my project, i have a file called
I have a program called test.c, and an input file called test.in. I'm trying

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.