Cpp Program To Do String Manipulations

  • Uploaded by: Saiyasodharan
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Cpp Program To Do String Manipulations as PDF for free.

More details

  • Words: 338
  • Pages: 4
STRING MANIPULATIONS USING POINTERS #include #include #include<string.h> #include<stdio.h> int strcompare(char *, char *); void strcopy(char *, char *); void strconcatenate(char *, char *); int strlength(char *); int strfindchr(char *, char); int strfindstr(char *, char *); void main() { char a[100], b[100], ch, str[100]; cout<<"\nEnter String 1: "; gets(a); cout<<"Enter String 2: "; gets(b); if(strcompare(a, b) == 1) { cout<<"\nTwo Strings are equal"; } else { cout<<"\nTwo Strings are not equal"; } strcopy(a, b); cout<<"\nFirst String after Copy: "<>ch; if(strfindchr(a, ch) == NULL) { cout<>str; if(strfindstr(a, str) == NULL) {

cout<<str<<" not found"; } else { cout<<str<<" is found at position "<<strfindstr(a, str); } } int strcompare(char *a, char *b) { int equal = 1, i=0; if(strlength(a) != strlength(b)) { return 0; } while(*(a+i) != '\0') { if(*(a+i) != *(b+i)) { equal = 0; break; } i++; } return equal; } void strcopy(char *a, char *b) { int i=0; while(*(b+i) != '\0') { *(a+i) = *(b+i); i++; } *(a+i) = '\0'; } void strconcatenate(char *a, char *b) { int i=0, j=0; while(*(a+i) != '\0') i++; while(*(b+j) != '\0') { *(a+i) = *(b+j); i++; j++; } *(a+i) = '\0';

} int strlength(char *a) { int len=0, i=0; while(*(a+i) != '\0') { i++; len++; } return len; } int strfindchr(char *a, char b) { int found=0, i=0; while(*(a+i) != '\0') { if(*(a+i) == b) { found = 1; break; } i++; } if(found == 0) return NULL; else return i+1; } int strfindstr(char *a, char *b) { int found=0, i=0, j=0, pos; while(*(a+i) != '\0') { found = 1; if(*(a+i) == *(b+j)) { pos = i+1; while(*(b+j) != '\0') { if(*(a+i) != *(b+j)) { found = 0; goto out; } i++; j++; }

goto out; } found=0; i++; } out: if(found == 0) return NULL; else return pos; } For more programs visit http://www.gethugames.in/blog

Related Documents

Cpp
May 2020 23
Cpp
December 2019 37
Cpp
June 2020 25
Cpp
October 2019 39

More Documents from ""