A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Curry

  • one year ago

Why does my array print differently just by simply adding a useless printf?

  • This Question is Closed
  1. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    By having that printf statement, my code prints out the correct sorted array. without it, it acts weird. I read something about it not being synchronized, but how do i fix that?

  2. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @wio

  3. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    any ideas wio? i've been stuck on this for so loong. :( also i need help writing an assembly method that gets the min value from an array. but this problem is my main focus rn.

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm not sure. I don't see how the print statement would change anything.

  5. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    should i take a screen shot of the different messages?

  6. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    somewhere on stackoverflow it said that the printf has a synchonized(this) in its actual code. so, it lets the thread know it's the same.

  7. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    and without it, the variables stay separate and get cached or something.

  8. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://meta.stackoverflow.com/questions/269174/questions-about-threadloop-not-working-without-print-statement << this was the post. howeve,r i can't fix it evne reading this.

  9. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You're not using Java though, right? Also, are you doing a multi-threaded program?

  10. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i'm not sure. what is meant by a multithreaded program. i'm doing c.

  11. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm calling the insert functions many times, yes.

  12. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    If it is a single threaded program, you don't need to worry about syncronization.

  13. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    how do i know if it is multi-threaded prog?

  14. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It will create a thread. Something like pthread in C

  15. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    well it seems like i am running a multi-threaded program then. i don't know where it says pthread, but it's not wokring without the print statement.

  16. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    wait, would you happen to know how ot write basic assembly code?

  17. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    If you haven't learned about threads yet, then you shouldn't be having a synchronization issue in your class.

  18. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    we learned about threads in previous classes, but nothing was mentioned about it in this one.

  19. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    but um, i'll try to figure this out. However, i really need help with writing an assembly code that gets the min value from an array. i know how to do arithmetic operations. however i do not know how to do get teh value. Any help?

  20. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I can help you come up with a better insert function.

  21. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ok!

  22. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ``` void resize(list *ls) { ls->maxSize = ls->maxSize * 2; ls->sortedList = (int *) realloc(ls->sortedList); } int insert(list *ls, int val) { int position; // insert position int i; // index used for shifting array if (ls->size == ls->maxSize) { resize(ls); } // find the insertion position for (position= 0; position < ls->size; position++) { if (ls->sortedList[position] > val) { break; } } // shift the elements after insertion points over for (i = ls->size; i > position; i--) { ls->sortedList[i + 1] = ls->sortedList[i]; } // set array value ls->sortedList[position] = val; ls->size++; return position; } ``` You shouldn't check for a pointer to be `null`. Ultimately, you should never pass a null pointer into a function which requires a non-null value.

  23. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hmmm, I think one line I put was wrong. ``` ls->sortedList[i + 1] = ls->sortedList[i]; ``` Should be ``` ls->sortedList[i] = ls->sortedList[i - 1]; ```

  24. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You should create a new question for your assembly thing.

  25. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ok!

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.