Thread: formatting code

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    vancouver wa
    Posts
    221

    formatting code

    My teacher said that i should go to
    Tools → Options → Text Editor → C/C++ → Tabs

    put 4 in for "Tab size", and 4 in for "Indent size" If you pick 4, then you should select "Keep tabs". I think he also said that VS will line up the code when it saves.
    My code is formatted horribly. Do i have to do this by hand?
    Code:
    bool list::remove (const char * const name)
    {
    	
    	//search for the data to be removed
    	node * prev = NULL;
    	node * curr = headByName;
    	while (curr)
    	{
    		
    	
    		if(strcmp(curr->item.getName(), name) == 0)
    		{
    			//remove the data
    			if(!prev)
    				headByName = curr->nextByName;
    			else
    				prev->nextByName = curr->nextByName;
    			delete curr;
    		  return true;
    		
    		}
    
    		prev = curr;
    		curr = curr->nextByName;
    	}
            return false;
    
    
    
    }
    to something like:

    Code:
    bool list::remove (const char * const name)
    {
    	
    	//search for the data to be removed
    	node * prev = NULL;
    	node * curr = headByName;
    	while (curr)
    	{
    	  if(strcmp(curr->item.getName(), name) == 0)
    	  {
    		if(!prev)
    		headByName = curr->nextByName;
    		else
    		prev->nextByName = curr->nextByName;
    		delete curr;
    		return true;
    	  }
    
    		prev = curr;
    		curr = curr->nextByName;
    	}
    	        return false;
    
    
    
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It probably won't change what's already there, no. There might be a "Re-indent" feature in Visual Studio but I don't know where it is.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    4 for tab size, using *spaces*, for four tabs.

    And it's...Ctrl-A to select all, then Ctrl-K,Ctrl-F to Format Selection in VS.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Location
    vancouver wa
    Posts
    221
    Amazing....
    thank you, rags_to_riches

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM