Thread: strlen help...
View Single Post
Old May 31st, 2006, 6:11 PM   #3
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
This capitalizes all of the words in a string.
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

char *capitalize(char *dest)
{
	char *p=dest;
	char last=0;
	for(;*p;p++)
	{
        *p=tolower(*p);	    
		if( isalpha((int)*p) && isspace(last)|| last ==0)
		{
		    *p=toupper(*p);
		}				
		last=*p;
	}
	return dest;
}

int main()
{
	char test[32]={0x0};
	char *p=NULL;
	strcpy(test,"HELLO how are u?");
	p=capitalize(test);
	printf("%s\n",p);
    return 0;
}

Sorry no strlen()...
jim mcnamara is offline   Reply With Quote