![]() |
Can anybody out there please help me? :(
For uni module I got to modify a program to enable initial capitalisation no matter what mix of cases is used. :
#include <stdio.h>I cannot program for all the sand in the sahara. I need this done immediately and I cannot get coding to work properly. Tried puting in the coding for capitalisation but it locks up and crashes. Thanks, shadowhunter. |
I'm not sure if this is exactly what you need, but it should be close enough to give you the idea of what you should be doing:
:
#include<stdio.h>Good luck! Edit: In case you're wondering where the >= 90 and the -30 came from, all the lowercase letters are represented by numbers from 97 to 122, the capitols from 65 to 90. Hence, to get from one to another, you subtract or add 32 (97-65=32) These numeric representations for letters are called ASCII codes. You can check out the ascii character code table here: The ASCII table |
Also, under Ctype.h there is a function called toupper() which makes a character uppercase.
|
Fixed code tags in the original post.
|
Here's some simple code to set a word to Title case:
:
if ((string[0] >= 'a') && (string[0] <= 'z')) { |
Create a function that accepts a string as a parameter. Inside the function... compare the ascii value of the first position in the string... if not uppercase, do the necessary calculation on the ascii value... using strcat build a new temp string... then return the temp string to the calling function... in this case, it would be the main function right before you wanted to print the results of the names.
|
Making a function that builds a temp string seems a bit heavy handed for a little program like this, i think. Though it sure is better coding pratice then when i pretty much just cut-and-pasted. I tell my friends never to cut and paste code but I'm guilty of it too often. Damn being a hypocrit... :)
|
| All times are GMT -5. The time now is 4:23 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC