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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:56:20+00:00 2026-06-01T12:56:20+00:00

/edited/ I’m new here. I have a text file that reads: 6 <cr> R

  • 0

/edited/
I’m new here.
I have a text file that reads:

6
<cr>
R 0
R 1
R 4
R 36
R 0
R 4

This is what I have. I want to read each line into an array so that I can convert that array into an integer so I can print only the numbers of whichever line I want later.

    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>


    int main()
    {
        FILE *fr;   /*declares file pointer*/
        int i, j, num[32];
        char array[32][32], input_file[32], line[32];
        printf("Enter file: ");
        fflush(stdin);
        scanf("%s", input_file);    
        fr = fopen(input_file, "r");
        for(i=0;i<32;i++)
            for(j=0;j<32;j++){
                array[i][j] = \'0';
            }
            for(i=0;i<32;i++){
                line[i] = '\0';
            }
        if(fr != NULL){

            while(fgets(line, sizeof(line), fr) != NULL){
                strcpy(array[i],line);
                    num[i] = atoi(array[i]);
                        i++;
                        printf("%d\n", num[i]);
            }
        }fclose(fr);
        else{
            perror(input_file);
        }
    }

I’m not getting any errors but it isn’t printing the right thing; this is what it prints:

-370086
-370086
-370086
-370086
-370086
-370086
-370086
-370086

Can anyone explain to me what is going wrong?

  • 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-01T12:56:21+00:00Added an answer on June 1, 2026 at 12:56 pm

    I think I’d handle this a bit differently. Though you haven’t stated it explicitly, I’m going to assume that the first number is telling us how many more lines of letters/numbers we’re going to read (not including the blank line). So, we want to read that, then read the rest of the lines, ignoring any leading non-digits, paying attention only to the numbers.

    If that’s correct, we can simplify the code somewhat:

    int num_lines;
    int i;
    int *numbers;
    
    fscanf(infile, "%d", &num_lines); // read the number of lines.
    
    numbers = malloc(sizeof(int) * num_lines); // allocate storage for that many numbers.
    
    // read that many numbers.
    for (i=0; i<num_lines; i++)
        fscanf(infile, "%*[^0123456789]%d", numbers+i);
        // the "%*[^0123456789]" ignores leading non-digits. The %d converts a number.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited Post These are the new functions that I have created using your template
EDITED QUESTION Hi this is the total workflow of this project we have a
Edited this question because of my bad examples.. Here is my updated question: Would
EDITED: Java httpPost into .asp form I am making an application that will display
(edited) I want to display a dynamic list of JPanels that hold textfield that
edited : My file has several lines. I encrypt the file onto a new
EDITED : The problem is with the function 'find_callback', I want to insert each
/* Edited to make sense! */ I 900 lines of this: ;745;ref;name;Adress;zipcode;;mobphone;;;;;;;;; i want
Edited for a larger tree, for more examples. I have a tree structure that
[edited] I am trying to make a script that downloads a file, the problem

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.