#include <stdio.h>
#include <math.h>


FILE *input, *output;

main()
{

int Max, Min, x[1000000],i=1,n=0,j=0;

input = fopen ("Nube_de_Caminantes.txt","r");

n=getw(input);

while (n !=EOF)
{
      fscanf(input, "%i",x[i]);
      i++;
      n = getw(input);
}



fclose(input);

}

There is some stuff I need to do with the array once I have it, but I can't get this to work. It compiles fine but it crashes if I try to run it. I'm quite the newbie when it comes to C, any help is welcome. Thank you.

No error message, just crashes? Nothing to give you an indication why? That's really strange. Try to pinpoint what statement causes the problem.

#include <stdio.h>
#include <math.h>


FILE *input, *output;

main()
{

int Max, Min, x[100000],i=1,n=0,j=0;

input = fopen ("Nube_de_Caminantes.txt","R");
output = fopen ("Histograma.txt","W");
n=getw(input);

while (n !=EOF)
{
      fscanf(input, "%i",x[i]);
      i++;
      n = getw(input);
}


fclose(input);
for (i=1; i<=10; i++) fprintf(output,"%i\n", x[i]);
fclose(output);
}

Ok, by changing the size of the array and changing the "w" and "r" to capital letters, it no longer crashes. So I proceeded to alter the code to write some numbers into an output file to check if I'm reading the data correctly, however, now it does nothing. Thanks.

probably good idea to check return codes for errors. For example if you are not able to open the file...

> changing the size of the array

This is right. In your original code you were trying to allocate 4 megabytes of data on the stack. The default stack size is 1 meg.

Okay, now the only thing that doesn't work is the file-reading bit, all the values for the array come back as zero. Any suggestions? Thank you! Quick edit:

I played around with it, and realized it will crash only if the input file contains more that two numbers. All the output values come out blank regardless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.