0

I need to store numbers from the text file to array to compare with another file to know how many numbers in this two files is the same number. One is a text file and another one is a binary file, So I think I need to use fgets to read it and store it in my array to compare the two of them But I don't know how to store it into the array.

This is an example of information in the file

472287848
348806518
873619952
462254724
701436029
537313066

and I try this one

#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *fp;
    char text[1000001];
    char buffer[1000];

    fp = fopen("txt100000.txt", "r");
    for(int i =0; i<1; i++)
    {
        fgets(text, 1000001, fp);
        buffer[i]=text;
    }

    fclose(fp);
    
        for(int i =0; i<strlen(buffer); i++)
    {
        printf("%s", buffer[i]);
    }

}

can you tell me how to make it work please?

Paz
  • 801
  • 1
  • 10
  • 14
  • https://stackoverflow.com/questions/571945/getting-a-stack-overflow-exception-when-declaring-a-large-array – Lundin Oct 20 '21 at 12:51
  • Apart from that always check if fopen and fgets succeeded or not. – Lundin Oct 20 '21 at 12:52
  • 1
    `fgets` reads a line into a character array (`text`). You then store the **address** of that string **as a single character** in the character array `buffer`. C strings handling is not the more beginner friendly part... Furthermore, as you want to process numbers, `scanf` could allow to convert the numbers from the file into integers that would be easier to store in an array... IMHO you should read about `scanf`... – Serge Ballesta Oct 20 '21 at 12:54

0 Answers0