AllExperts > C 
Search      
C
Volunteer
Answers to thousands of questions
 Home · More C Questions · Answer Library  · Encyclopedia ·
More C Answers
Question Library

Ask a question about C
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Prince M. Premnath
Expertise

I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience
Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

 
   

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


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.