Bawnawgwa's Profile User Rating: -----

Reputation: 8 Worker
Active Members
Active Posts:
142 (0.15 per day)
21-January 13
Profile Views:
Last Active:
User is offline Mar 05 2015 10:28 PM

Previous Fields

Dream Kudos:
Icon   Bawnawgwa has not set their status

Posts I've Made

  1. In Topic: Freeing allocated memory in doubly linked list in C.

    Posted 22 Feb 2015

    Hmm alright, I set up my data in a separate struct, this has the bonus of making nodes a lot nicer to look at while debugging. However, the big issue I am having right now is setting up a parent.

    Where I set neighbor->parent = current_node is the basis of the A* algorithm, however, I remove current_node from open_list each loop, thus it must be freed, but freeing it destroys neighbors parent.

    I have done some modifications and completely got rid of all my random mallocs and ONLy have malloc in the list_add function and it works, BUT no node has a parent because the parent gets destroyed each loop by having a free(current_node) at the end of the while loop. Hmm...

    I need some way to copy the x and y coordinates of current_node into a "parent-like" reference of the neighbor node that will hold after current_node is freed. Perhaps all I need is a 'from_x' and 'from_y' variable in the struct array holding the data, in which I place the current x and y of current_node!

    Strike that, that still leaves me know way of moving back through nodes that were supposed to be connected through parent.
  2. In Topic: Freeing allocated memory in doubly linked list in C.

    Posted 22 Feb 2015

    Hmm I think I solved some of the problem by freeing current_node at the end of the loop. The program still seemed to work alright. But I still have some leaks with neighbor_nodes and lowest_f_node because I am currently mallocing a node in lowest_f_node so I can store all the values of the lowest node in a list and return it.

    Is there a way I can copy all the elements of a node into another, but not the address of the node (which node1 = node2 does and modifying node1 would change node2), without mallocing new space?

    And those mallocs all over the place are because I need to do something with the data in a node, but nothing but seg faults without the malloced space.
  3. In Topic: Finding and printing a substring in a string

    Posted 22 Feb 2015

    Also, the flag, don't '++' the flag. If you successfully compare every member of the substring with a part of the mainstring in order, THEN do flag = 1, else flag = 0.

    int k = 0, tmp = 0;
    for(int i = 0; i < mainstr_size; i++){
              if(mainstr[i] == substr[k]){
              if(k == substr_size){ //if you managed to get to the end of k you set flag, store next position of mainstr, and break out of loop
                    flag = 1;
                    tmp = i = 1; //you have the value of i stored so you can concatinate substring and mainstring starting at i till the end
              else if(mainstr[i] != substr[k]){
                   k = 0; //reset substring

    Then concatinate substring with rest of mainstring.

    I do not think you will want a nested for loop for this code. What I gave above will probably need kinks worked out to get it to your specifications, that was just a quick write up :P. I didn't do any testing with it. But it is the general idea for testing a if a string is within another string.
  4. In Topic: Reversing Array Contents

    Posted 22 Feb 2015

    It isn't necessary to pass i and farend by reference as all you need is their values and won't be modifying them within swap, but the array will need to be.
  5. In Topic: Reversing Array Contents

    Posted 22 Feb 2015

    Are you required to swap in another function? Otherwise swapping is only 3 lines of code, might as well just throw it in there instead of the function call. But otherwise, you could pass in the array by reference, the i value, and the 'far end'. i value and far end not needed to be by reference, then you access the array directly in the swap function and swap its stuff.

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information

Click here to e-mail me


Bawnawgwa hasn't added any friends yet.


Bawnawgwa has no profile comments yet. Why not say hello?