Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # include <iostream>
  2. # include <string.h>
  3. using namespace std;
  4.  
  5. int HowManyCapitalLetters(char str []);
  6. char* newSting(char str[],char*newStr);
  7.  
  8. void main()
  9. {
  10. char string [] ={"Good morning Sunshine Moshe"};
  11. char*newString;
  12. int size=0;
  13.  
  14. size = HowManyCapitalLetters(string);
  15.  
  16. newString= new char (size+1);
  17. newString[size+1]='\0';
  18.  
  19. newSting(string,newString);
  20.  
  21. cout<<"The new string is "<<newString<<endl;
  22.  
  23. delete []newString; //why i have a problem in the delete;
  24.  
  25. system("pause");
  26. }
  27. int HowManyCapitalLetters(char *string)
  28. {
  29. int i=0;
  30. int counter=1;
  31. while(string[i]!='\0')
  32. {
  33. if(string[i] == ' ')
  34. {
  35. counter++;
  36. }
  37. i++;
  38. }
  39. return counter;
  40. }
  41. char* newSting(char str[],char*newStr)
  42. {
  43. int j=0;
  44. int counter=0;
  45. int sizeStr=strlen(str);
  46. bool checkIfDiffrent =true;
  47.  
  48. for(int i=0;i<sizeStr;i++)
  49. {
  50. if(i==0)
  51. {
  52. newStr[counter]=str[i];
  53. counter++;
  54. }
  55. if(str[i] == ' ')
  56. {
  57. for(j=0;j<counter;j++)
  58. {
  59. 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!!!
  60. {
  61. checkIfDiffrent==false;
  62. }
  63. else
  64. {
  65. checkIfDiffrent==true;
  66. }
  67. }
  68. if(checkIfDiffrent)
  69. {
  70. newStr[counter]=str[i+1];
  71. counter++;
  72. }
  73. newStr[counter+1]='\0';
  74. }
  75. }
  76. return newStr;
  77. }
  78. /*
  79. The new string is GmSM
  80. Press any key to continue . . .
  81. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement