A community for students.
Here's the question you clicked on:
 0 viewing
A.Avinash_Goutham
 3 years ago
hey can any1 xplain me why i got a segementation fault?
i was using gcc btw
A.Avinash_Goutham
 3 years ago
hey can any1 xplain me why i got a segementation fault? i was using gcc btw

This Question is Closed

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0Most 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.

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0i took care f it r8? var < size in for loop? that's not good enough?

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0But what's the value of var when `var >= size`?

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0it's not var>=size it was var>=0

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0As 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)

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0and then it decreases in that while loop

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0it's not `size  1`, since `(size  1) < size`.

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0oh ok lemme try it but i got a printf for first iteration

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0hey thanks it worked......gimme a min

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0nelo? sry... m confused.....wat's ur name again?

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0slotema is just fine. What's the problem with that program?

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0it goes in to an infinite loop and prints weird symbols when i xpect some numbers.........

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0That'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.

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0did u check the file? the file has weird characters

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0i used a fprintf for that file

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0In 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.

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0ohh so i have to use a loop here?

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0Yep. Like you did in the print function.

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0what if a put a /0 in the end? will it work?

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0It 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'.

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0i changed the flag condition and i changed the print...

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0it;s stuck in a loop smwer?

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0Check the power function. The problem is in there.

slotema
 3 years ago
Best ResponseYou've already chosen the best response.0you can also use the pow function from math.h

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0yup i found it sry my net's goin crazy and it's still in an infinite loop

A.Avinash_Goutham
 3 years ago
Best ResponseYou've already chosen the best response.0i finallyy completed it........ thanks @slotema
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.