i forgot to implement this last pat
"else you call has_duplicate() for the previous character and return the return value of that recursive call."
on this function:
Code:
int has_duplicate(char string[], int index, char ch)
{
int check;
if (index<0)
{
return 0;
}
if (ch==string[index])
{
return 1;
}
else
{
check=has_duplicate(string,index-1,ch);
return check;
}
}//end func
now dont have any warnings
but i still dont have any output.
??
Code:
#include <stdio.h>
void remove_duplicates(char string[], int index);
void overwrite(char string[], int index);
int has_duplicate(char string[], int index, char ch);
int main()
{
int i,ch;
char input[255];
printf("enter string\n");
for (i = 0; i < 255 && (ch = getchar()) != '\n' && ch >=0; ++i)
{
input[i] = ch;
}
input[i] = '\0';
remove_duplicates(input,0);
printf("%s",input);
return 0;
}
void remove_duplicates(char string[], int index)
{
int flag = -1;
if (string[index] != '\0')
{
flag = has_duplicate(string, index, string[index]);
if (flag == 1)
{
overwrite(string, index);
remove_duplicates(string, index);
}
else
{
remove_duplicates(string, index + 1);
}
}
}
int has_duplicate(char string[], int index, char ch)
{
int check;
if (index<0)
{
return 0;
}
if (ch==string[index])
{
return 1;
}
else
{
check=has_duplicate(string,index-1,ch);
return check;
}
}//end func
void overwrite(char string[], int index)
{
if ( string[index]=='\0')
{
return;
}
if( string[index]!='\0')
{
string[index]=string[index+1];
overwrite(string,index+1);
}
}