anonymous
  • anonymous
hey can any1 xplain me why i got a segementation fault? i was using gcc btw
Computer Science
jamiebookeater
  • jamiebookeater
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
anonymous
  • anonymous
Most of the time, segmentation faults are caused by an array index that is too large. That's the case here as well. Check the values of `var` and try to figure out when that value is too large to access x/number.
anonymous
  • anonymous
i took care f it r8? var < size in for loop? that's not good enough?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
But what's the value of var when `var >= size`?
anonymous
  • anonymous
it's not var>=size it was var>=0
anonymous
  • anonymous
As long as `var < size`, the loop will run. But after the loop is finished, what is the value of var? (which you use on number in the second loop)
anonymous
  • anonymous
it's size-1
anonymous
  • anonymous
and then it decreases in that while loop
anonymous
  • anonymous
it's not `size - 1`, since `(size - 1) < size`.
anonymous
  • anonymous
oh ok lemme try it but i got a printf for first iteration
anonymous
  • anonymous
hey thanks it worked......gimme a min
anonymous
  • anonymous
nelo? sry... m confused.....wat's ur name again?
anonymous
  • anonymous
anonymous
  • anonymous
slotema is just fine. What's the problem with that program?
anonymous
  • anonymous
it goes in to an infinite loop and prints weird symbols when i xpect some numbers.........
anonymous
  • anonymous
That's a problem in `print_alt`. You're trying to print a string there ("%s"). A string in C is basically an array of characters ended by an element with the value 0 or '\0' (but not ended by '0'). Since number does not have a 0 at it's end, it'll keep printing something until the printf encounters a 0.
anonymous
  • anonymous
did u check the file? the file has weird characters
anonymous
  • anonymous
i used a fprintf for that file
anonymous
  • anonymous
In your fprintf, the same thing is happening. You're trying to print an array as if it were a string. That's not going to work.
anonymous
  • anonymous
ohh so i have to use a loop here?
anonymous
  • anonymous
Yep. Like you did in the print function.
anonymous
  • anonymous
what if a put a /0 in the end? will it work?
anonymous
  • anonymous
It should stop printing, but what it's printing won't be readable numbers. If you're trying to print the integer 1 as a character, it won't show up as '1'.
anonymous
  • anonymous
i changed the flag condition and i changed the print...
anonymous
  • anonymous
it;s stuck in a loop smwer?
anonymous
  • anonymous
Check the power function. The problem is in there.
anonymous
  • anonymous
you can also use the pow function from math.h
anonymous
  • anonymous
yup i found it sry my net's goin crazy and it's still in an infinite loop
anonymous
  • anonymous
i finallyy completed it........ thanks @slotema

Looking for something else?

Not the answer you are looking for? Search for more explanations.