| |
You are here: Experts > Computing/Technology > C/C++ > C > Strings in C
C - Strings in C
Expert: Prince M. Premnath - 10/24/2009
Question sir, I am Major MTC De Silva from Sri lanka Army.Now I am under going Bsc in Computer Science in University in Bangladesh..
I have a problem in adding two string,Multiple two string,How to convert the first letter in each word in a sentence to the Uppers case and other way also...
Sir could u kindly send me the system for handling the pointers with string,pointer with array also..
I hope u are reply soon for me..
Thanks a lot sir
Major Thushan De Silva psc.
Answer Hi dear Thushan.
Here is the code i ve programmed for string manipulations what you have mentioned, please have a look.
Note: in C We cannot add two strings like this str1+str2; which requires overloading of '+' which wasn't supported in C. so ive programmed the strcat() function.
#include <stdio.h>
char* Strcat(char* src , char* dest)
{
char* ptr = dest;
while(*++dest);
while(*dest++ = *src++);
*dest='\0';
return ptr;
}
char* ProperCase(char* src)
{
char* ptr = src;
if((*ptr >= 65) && (*ptr <= 122))
*ptr = *ptr - 32;
else if((*ptr >= 97) && (*ptr <= 122))
*ptr = *ptr +32;
while(*ptr++)
{
if(*(ptr-1) == ' ')
{
if((*ptr >= 65) && (*ptr <= 122))
*ptr = *ptr - 32;
else if((*ptr >= 97) && (*ptr <= 122))
*ptr = *ptr +32;
}
}
return src;
}
void main()
{
clrscr();
// printf("%s",Strcat("Source","destination"));
printf("%s",ProperCase("this is a sample"));
getch();
}
I suggest you to follow the link for better understanding in Pointers and Strings , Array's
http://www.cdf.toronto.edu/~csc209h/summer/lectures/w4/w4.pdf
Get back to me in case of issues
Thanks and Regards
Prince M. Premnath
Add to this Answer Ask a Question
|
|