i am wrting a small function that takes a string in lowercase then i want to change it to uppercase. How do i do that?
i am wrting a small function that takes a string in lowercase then i want to change it to uppercase. How do i do that?
Take a look at the standard function toupper();
try thatCode:int stringtoupper(char *str) { while(*str) { *str = toupper(*str); *str++; } return 0; }
usage:
Code:stringtoupper(str);
dont forget to
example:Code:#include <ctype.h>
Code:#include <stdio.h> #include <stdlib.h> #include <ctype.h> int stringtoupper(char *str) { while(*str) { *str = toupper(*str); *str++; } return 0; } int main(int argc, char *argv[]) { char s[] = "hElLo"; stringtoupper(s); printf("%s\n",s); system("PAUSE"); return 0; }
Last edited by Brian; 02-25-2002 at 04:11 PM.
*str++;
should be .....
str++;
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
strupr(str), strlwr(str) will perform full string upper/lower conversion without the increment char by char thing.
its' in ctype or string.h
-