Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- # include <string.h>
- using namespace std;
- int HowManyCapitalLetters(char str []);
- char* newSting(char str[],char*newStr);
- void main()
- {
- char string [] ={"Good morning Sunshine Moshe"};
- char*newString;
- int size=0;
- size = HowManyCapitalLetters(string);
- newString= new char (size+1);
- newString[size+1]='\0';
- newSting(string,newString);
- cout<<"The new string is "<<newString<<endl;
- delete []newString; //why i have a problem in the delete;
- system("pause");
- }
- int HowManyCapitalLetters(char *string)
- {
- int i=0;
- int counter=1;
- while(string[i]!='\0')
- {
- if(string[i] == ' ')
- {
- counter++;
- }
- i++;
- }
- return counter;
- }
- char* newSting(char str[],char*newStr)
- {
- int j=0;
- int counter=0;
- int sizeStr=strlen(str);
- bool checkIfDiffrent =true;
- for(int i=0;i<sizeStr;i++)
- {
- if(i==0)
- {
- newStr[counter]=str[i];
- counter++;
- }
- if(str[i] == ' ')
- {
- for(j=0;j<counter;j++)
- {
- if(str[i+1]== newStr[j]|| str[i+1]+('a'-'A') == newStr[j]||str[i+1]-('a'-'A') == newStr[j])//why it isnt getting in to the condition!!!
- {
- checkIfDiffrent==false;
- }
- else
- {
- checkIfDiffrent==true;
- }
- }
- if(checkIfDiffrent)
- {
- newStr[counter]=str[i+1];
- counter++;
- }
- newStr[counter+1]='\0';
- }
- }
- return newStr;
- }
- /*
- The new string is GmSM
- Press any key to continue . . .
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement