Thread: Writing a function for the specifics..?

  1. #1
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235

    Question Writing a function for the specifics..?

    Can anyone help me write a function that does the following, any ideas...?

    1.Its supposed to capitalize every letter at the beginning of a sentence.
    2. Insert a space after every punctuation mark except for dashes (-) and single quote (').
    3. Capitalize every letter after each of the punctuation marks.

    can anyone help, plsss, sugestions ideas...?

    My code below, ok ppl im asking you to help, not do everything then!

    Code:
    void makeproper ( char *in)
    
    {
    
     
    
         
    
    if ( islower( *in) ){
    
    *in = toupper( *in );
    
                    }
    
         
    
         while ( *in ){
    
              
    
              if( ispunct( *in++ ) ){
    
                  if( *in != '\'' && *in != '-' ){ /* next must be space */
    
                  /**need_space = 1;
    
                  need_upper = 1;**/
    
    
    
                  putchar (' ');
    
                          if ( islower( *in ) ){
    
                          *in = toupper( *in );}
    
                    }
    
    
    
                    else{
    
                    /**need_space = 0;
    
                    need_upper = 1;**/
    
                    if ( islower( *in ) ){
    
                    *in = toupper( *in );
    
                    }
    
                    }
    
                    }
    
    
    
    else
    
    if(ispunct( *in++ ) && isspace( *in++ ))
    
    {
    
    if( *in != '\'' && *in != '-' ){ 
    
        
    
        if ( islower( *in ) )
    
               {
    
                    *in = toupper( *in );
    
                    }
    
    }
    
    
    
    }
    
    
    
    ++in;    
    
               }/**end while**/
    
    
    
    
    
    } /**end of make proper**/
    Last edited by Matus; 03-04-2008 at 08:21 PM. Reason: People said to post the codes i have already!!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    1. First figure out how to find the start of a sentence. That might be specially defined in the assignment.
    2. Char by char analysis is probably a good way to go about it.
    3. See above suggestion.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Please, please, please, post your best attempt at coding your assignment before posting to the forums. You will not get far otherwise. Also read over the FAQs prior to posting as well.

  4. #4
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Dude ok im not asking you to do everything, check the code i have and help me modify it please, that is if you got time, thanks!

  5. #5
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by slingerland3g View Post
    Please, please, please, post your best attempt at coding your assignment before posting to the forums. You will not get far otherwise. Also read over the FAQs prior to posting as well.
    Ok can you see the code i posted now, can you help me modify it please, thanks!!

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Your horrible indention is going to make this pretty hard on yourself since you won't be able to easily follow the code.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Read and learn:
    Code:
    void makeproper (char *in)
    {
    	if ( islower( *in) )
    	{
    		*in = toupper( *in );
    	}
    
    	while ( *in )
    	{
    		if( ispunct( *in++ ) )
    		{
    			if( *in != '\'' && *in != '-' )
    			{ /* next must be space */
    				/**need_space = 1;
    				need_upper = 1;**/
    				putchar (' ');
    
    				if ( islower( *in ) )
    				{
    					*in = toupper( *in );
    				}
    			}
    			else
    			{
    				/**need_space = 0;
    				need_upper = 1;**/
    				if ( islower( *in ) )
    				{
    					*in = toupper( *in );
    				}
    			}
    		}
    		else
    			if(ispunct( *in++ ) && isspace( *in++ ))
    			{
    				if( *in != '\'' && *in != '-' )
    				{
    					if ( islower( *in ) )
    					{
    						*in = toupper( *in );
    					}
    				}
    			}
    		++in;    
    	}/**end while**/
    } /**end of make proper**/
    Removed horrible multiple lines between each line of code and fixed indentation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    if ( islower( *in ) )
    {
       *in = toupper( *in );
    }
    you do not need if - toupper will do this check anyway
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. help with writing function that multiplys the radius
    By Earl Lee in forum C Programming
    Replies: 6
    Last Post: 10-03-2002, 04:33 PM