Thread: Code colouring

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    /*Split from http://cboard.cprogramming.com/showt...t=82493&page=2 ~ kenfitlike*/

    It is just your code, but painted:
    Code:
    #include <iostream>
    using namespace std;
    
    struct node {
      int x;
      node* next;
    };
    
    void createList( node* root, int size ){  //Creates a list of any size
    
      for(int i = 0; i < size; i++){
        root->x = i + 1;
        root->next = new node;  //Creates a new node at the end of the list
        root = root->next;  //Moves to that node
        root->next = 0;  //Sets the end of the list at the current node
      }  //for
    
    }
    
    void cleanList( node* root ){  //Clears the list from memory
    
      if( root != 0 ) {
    
        while( root->next != 0 ){
          node* temp = root;  //Assigns temp to be the current head
          root = root->next;  //Moves the head to the next element
          delete temp;  //Deletes the temporary head
        }  //while
    
      }  //if
    
    }
    
    void displayList( node* walker ){  //Displays all the elments of the list
    
      while(walker->next != 0 ){
        cout << walker->x << endl;
        walker = walker->next;  //Moves to the next element
      }  //while
    
    }
    
    node* addToList( node* head, int value ){  //Adds a new node to the 
                                               // beginning, the middle or the end
                                               // of the list
    
      node* search_ptr = head;  //search_ptr points to the first node
    
      node* newNode = new node;  //Creates new node
    
    //If the new value is less than or equal, or greater than the value in the first
    // node, then:
      if( value <= search_ptr->x ) {  
          newNode->x = value;           //Inserts this new value at the first node
          newNode->next = head;         // and makes the next pointer in newNode
                                        // to point to the beginning of the list
      } else {
    
        node* past_node;  //This node stores the last node accessed
    
        while( search_ptr->next != 0 ){  //While is not the end of the list
    
          past_node = search_ptr;  //past_node equals the current node
          search_ptr = search_ptr->next;  //Moves to the next node
    
    //If the value is less than or equal to the next value in the node, then
    // inserts the new node in the middle of the list
          if( value <= search_ptr->x ){  
    
            past_node->next = newNode;   //Last element in the node points to the
                                         // new node
            newNode->x = value;          //The new node gets the value
            newNode->next = search_ptr;  //The next pointer of the new node points
                                         // to the next element in the list
    
            return head;  //Returns the whole list
          } //if
    
        }  //while
    
    //If we get to the last node in the list and the results from the comparissons
    // were all false, then it means that this value must be placed at the end of
    // the list
        if( head->next == 0 ){
          newNode->x = value;           //Inserts this new value at the first node
          newNode->next = head;         // and makes the next pointer in newNode
        } else {
        newNode->x = value;  //The new node gets the value
        search_ptr->next = newNode;  //Search_ptr is now the last element in the
                                     // in the list, so we make the next pointer
                                     // of the last element to point to the newNode
        newNode->next = 0;           // and newNode becomes the last element in the
                                     // list
    
        return head;  //Returns the whole list
        }
      }
    
      return newNode;  //Returns the address of the new first node
    }
    
    int main(){
      node* head;  //First node in the list
      
      head = new node;  //Creates the first element
      
      createList( head, 1 );
    
      head = addToList( head, 10 );
      head = addToList( head, 6 );
    
      displayList( head );
    
      cleanList( head );
      
      cin.get();
    
    }
    [edit]
    I am just testing my code painter.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Thread hijacker . . . .

    How does your program handle this?
    Code:
    printf("hi");
    
    #define /*what?*/ foo
    
    puts("\\\"");
    
    in\
    t x;
    
    printf("/*comment*/");
    
    /* int x; printf("int x;"); */
    
    // /*
    for(;;){}
    //*/
    
    /*//*/ int okay;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I don't have a compiler on me ... what does it do? How does the #define with the /**/ handle? I'm assuming you're talking about the color coder (go for this one. It's much better Color Coder v2.0 (C++).) rather than the linked list forgot the oftopic tags

    [offtopic]How does your one handle it, dwks [/oftopic]

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I was suggesting that siavoshkc try that in his code colouring program.

    codeform handles it pretty well, but not perfectly. It's still a work in progress.

    go for this one. It's much better Color Coder v2.0 (C++).
    Are you kidding?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    New version, less "undocumented features"!

    EDIT :: fixed terminology, thanks dwks
    Last edited by twomers; 09-04-2006 at 01:40 PM.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Really.

    I posted the code into the colour coder you mentioned, and it locked into an infinite loop.

    At least codeform just messes up, it doesn't freeze my computer.

    EDIT :: fixed terminology, thanks dwks
    You're welcome. Now they're documented features, eh?
    Last edited by dwks; 09-04-2006 at 01:42 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Well, that's a pretty nasty bit of code, lets be honest. I messaged the code to the maker. You're just mean, dwks!!

    I've never made a linked list. Never saw the point with vectors and lists anyways. I'm thinking I may try though ... :/ not sure if it's worth the time though. It's not gonna be as good as the STL


    [OT]>> Now they're documented features, eh?
    Well, of course not!! Have you seen documentation detailing them?[/OT]

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    [OT]>> Now they're documented features, eh?
    Well, of course not!! Have you seen documentation detailing them?[/OT]
    Yes, actually. Somewhere I saw something like "it may lock into an infinite loop, allocating memory infinitely. If this happens, quickly launch task manager by right-clicking on the taskbar, find Color Coder, and click on end task." Really. I'm not kidding. And the source code isn't available for it, so we can't help fix it.

    [edit] Yes, from the readme.txt:
    Please do NOT ask for the Source Code. This is not an opensource project.

    [...]

    If program seems to crash, CTRL + ALT + DEL and end process "Color Coder v2.0.exe", or it will grow in size very fast until it exhausts all of your physical and virutal memory. May cause PC to be extremely slow and/or crash when all of memory is exhausted.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I'm impressed. Semantic, as I said on your forums! (perhaps we should stop talking off topic ... the OP may still need to lean something and wouldn't want to get the topic closed :/)

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay, agreed. Sorry, Martin. [edit=2] Martin wrote Color Coder: http://martin.thejefffiles.com/About.html [/edit]

    [edit]
    How does the #define with the /**/ handle?
    The preprocessor strips comments before it handles preprocessor directives such as #define. That's why this is valid:
    Code:
    #ifdef WIN32
        #include <windows.h>
    #endif  /* #ifdef WIN32 */
    [/edit]
    Last edited by dwks; 09-04-2006 at 01:57 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Thanks, Ken!

    >> go for this one. It's much better Color Coder v2.0 (C++).
    I didn't mean that against codeform, BTW

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    No, I know that.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    yeah liek i totaly pwn you guys i fixed it.

    http://martin.thejefffiles.com/CCv2.0.zip
    My Website
    010000110010101100101011
    Add Color To Your Code!

  14. #14
    -AppearingOnThis..........
    Join Date
    May 2005
    Location
    Netherlands
    Posts
    44
    This probably goes under the category of 'lame', but here's a web based version if it's of any interest (not nearly as advanced as dwks's, but it could be worse).

  15. #15
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Oh I noticed this thread just now.
    I have written a code painter and it is in debugging phase.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM