Bus error 10

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 6880 Views - Last Post: 27 February 2014 - 07:57 AM Rate Topic: -----

#16 Anonymous1337   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 16-November 13

Re: Bus error 10

Posted 27 February 2014 - 06:20 AM

View Posttarmizi_adam2005, on 27 February 2014 - 04:53 AM, said:

Hi,

You might also want to check if you have successfully opened the file properly. This could be an example on how to do it.

I did test it it works sorry for the late response I attached the input file
Was This Post Helpful? 0
  • +
  • -

#17 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: Bus error 10

Posted 27 February 2014 - 06:29 AM

Do not open posts about the same topic. Merging threads...
Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: Bus error 10

Posted 27 February 2014 - 07:57 AM

You also are using a variable that is not initialized. Look at this snippet:
    int month[32];
... 
    while(month[i]!=-1){


You have never assigned a value to month[i] at this point. You'll need to rearrange your fscanf() call in your loop to the end of the loop, after you increment i. And you'll need to read the first entry before the loop.

Also look at this snippet:
        if(month[i] == month[i-1]){

The first time through your loop you will be trying access your array with a negative index, which is illegal. This is not the first place you've made this mistake, re-read post #2 and post #3. I quit reading your code at that point, but I do see you're doing the same thing over and over again.

Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2