Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

function that capitalizes all words of a string

#include <stdio.h>
#define MAX 100

char *capitalize(char *s)
{
	char str[MAX]={0};	
	int i;
	
	//capitalize first character of words
	for(i=0; str[i]!=''; i++)
	{
		//check first character is lowercase alphabet
		if(i==0)
		{
			if((str[i]>='a' && str[i]<='z'))
				str[i]=str[i]-32; //subtract 32 to make it capital
			continue; //continue to the loop
		}
		if(str[i]==' ')//check space
		{
			//if space is found, check next character
			++i;
			//check next character is lowercase alphabet
			if(str[i]>='a' && str[i]<='z')
			{
				str[i]=str[i]-32; //subtract 32 to make it capital
				continue; //continue to the loop
			}
		}
		else
		{
			//all other uppercase characters should be in lowercase
			if(str[i]>='A' && str[i]<='Z')
				str[i]=str[i]+32; //subtract 32 to make it small/lowercase
		}
	}
	
	printf("Capitalize string is: %s
",str);
	
	return 0;
}
Source by www.includehelp.com #
 
PREVIOUS NEXT
Tagged: #function #capitalizes #words #string
ADD COMMENT
Topic
Name
7+6 =