Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 31st, 2006, 11:26 AM   #1
The_Razgriz_Ace
Newbie
 
Join Date: May 2006
Posts: 1
Rep Power: 0 The_Razgriz_Ace is on a distinguished road
strlen help...

Hi,

Im having a problem with an assignment...Im supposed to format a string...and this is doing my head in...

I have to use a for loop, use strlen to control which character to format...the thing is, the first character in the string MUST be uppercase and the rest lowercase, and naturally, we have to use toupper and tolower...

If you could provide even an example of how this would be implemented then I would be very happy...

Thanks in advance
The_Razgriz_Ace is offline   Reply With Quote
Old May 31st, 2006, 11:31 AM   #2
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Emazing! First Google Hit!
Cprogramming.com reference
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply

Last edited by Prm753; May 31st, 2006 at 11:42 AM.
Prm753 is offline   Reply With Quote
Old May 31st, 2006, 5: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
Old Jun 1st, 2006, 1:43 AM   #4
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 3 bivhitscar is on a distinguished road
Some pseudo code for you to ponder:

For i = 0, while i is less then the length of the string, increment i by 1 per loop.
If i is 0, change the letter to uppercase, otherwise change the letter to lowercase.

Without writing the actual code for you, that should get you well on your way.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC