You are here:

C/Strings in C

Advertisement


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

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


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

©2012 About.com, a part of The New York Times Company. All rights reserved.