in c++ how would i turn the funcion that uses [] to pointer notation #include void condense(char s[]); // Function prototype int main() { char s[]= "abcadmmdefagdbfffbdm"; // assign string condense(s); // Calling function std::cout<
in c++ how would i turn the funcion that uses [] to pointer notation
#include <bits/stdc++.h>
void condense(char s[]); // Function prototype
int main()
{
char s[]= "abcadmmdefagdbfffbdm"; // assign string
condense(s); // Calling function
std::cout<<s; // print string after upate the string
return 0;
}
void condense(char s[]) // Called function recieve string
{
int i,j,index = 0; // variable declaration
int n = strlen(s)+1; // n string length
for (i=0; i<n; i++) { // Loop runs for all characters
int count=0; // Initially count is 0
for (j=0; j<i; j++) // Loop to count number of times character appear
if (s[i] == s[j]){ // compare current character with all other characters
count++; // Increment count by 1
if(count==2) // if count is 2
break; // Stop iterating
}
if (j == i) // If both indexes same indicate the char not repeated more than twicw
s[index++] = s[i]; // keep it in char array
}
}
Step by step
Solved in 2 steps with 1 images