How would i go about changing a string to uppercase, no matter what case the characters are entered in the program??
Also how would i go about creating a username and password function?
THanks.
Printable View
How would i go about changing a string to uppercase, no matter what case the characters are entered in the program??
Also how would i go about creating a username and password function?
THanks.
tolower() and toupper() ignores the case as far as I know.
Creating username and passwd: Which plattform, *nix or Windows ? In Unix you could prepare a string and use system() for it, which'd be the easiest way
I'm using dev c++ on windows.
Where would i put the toupper?
Here is just a simple function I wrote:
:)Code:void convertToUppercase(char *sPtr)
{
while (*sPtr != '\0') { // current character is not '\0'
if(islower(*sPtr)) { //if character is lowercase
*sPtr = toupper(*sPtr); //convert to uppercase
}
++sPtr //move sPtr (pointer to the next character
} //end while
} //end function convertToUppercase
>How would i go about changing a string to uppercase, no matter what case the characters are entered in the program??
toupper in <ctype.h>.
>if(islower(*sPtr))
This test is not needed anymore for a simple case switch. toupper is guaranteed to return its argument unchanged if there is no suitable conversion. So your function could be simplified even more (with my own embellishments):
Code:char *stoupper ( char *s )
{
while ( *s != '\0' )
*s++ = toupper ( *s );
}
Code:(/* DISPLAY DESIGNER NAMES */
void f_display_designer ()
{
int num_i;
num_of_items_i1 = 1;
printf("______________________________________\n");
printf("DESIGNER INFORMAION\n");
printf("_______________________________________\n");
printf("\n");
for (num_i = 0; num_i < num_of_items_i1; num_i ++);
{
printf ("%s %s %s %s \n", designer[num_i].forename_s, designer[num_i].surname_s, designer[num_i].mobile_number_s, designer[num_i].area_s );
printf("__________________________________\n\n\n\n\n");
}
thats an example of my display code where would i add the peice of code?
If you want all output in upper case:
Code:printf ("%s %s %s %s \n",
stoupper ( designer[num_i].forename_s ),
stoupper ( designer[num_i].surname_s ),
designer[num_i].mobile_number_s,
designer[num_i].area_s );
Do i not need this part >>>
??Code:char *stoupper ( char *s )
{
while ( *s != '\0' )
*s++ = toupper ( *s );
}
of course you do
Great, where do i put it?
In the C Standard library, there are functions strupr() and strlwr() that convert strings to all-upper or all-lower case. The conversion is in-place (it modifies the original string).
Why not try one of these?
DaveCode:#include <stdio.h>
#include <string.h>
int main()
{
char string1[] = "This is string #1";
char string2[] = "This is string #2";
char string3[] = "This is string #3";
printf("Initial Strings: <%s> <%s> <%s> \n\n",
string1, string2, string3);
printf("Strings using functions: <%s> <%s> <%s> \n\n",
strupr(string1), strlwr(string2), string3);
printf("Strings after functions: <%s> <%s> <%s> \n",
string1, string2, string3);
return 0;
}
On the top, before int main(), or you can take it at the boun, and make a prototype at the global declare place, where you include headers/libaries etc.. Should look like this:
char *stoupper(char *s); //prototype
Then you can use it as much you want ;)
Cheers Dave that works a treat.
>Why not try one of these?
Because despite being in string.h on your compiler, they actually are not a part of the standard library.
Quote:
Originally posted by Prelude
>Why not try one of these?
Because despite being in string.h on your compiler, they actually are not a part of the standard library.
[edit]
Oops: now I see: string.h is in the standard; not strupr(), strlwr().
(But they are in Borland, Microsoft VC++, GNU gcc libraries, and I've used them from time to time).
Apologies, and thanks for the information
[/edit]
Dave