This is the origional question:
Write a function
repeating_group(char* arr[], int n);where,
arr[]: predefined array of string to operate onn: size of thearr[]and returns
char* res[]with repeating strings grouped together.Example:
input:
char* arr[] = {"tut", "slf", "tut", "lzyy", "slf", "tut"};output:
char* res[] = {"tut", "tut", "tut", "slf", "slf", "lzyy"}
This is my code:
#include<stdio.h>
char repeating_group(char*arr[],int n)
{
int i,j;
printf("char*res[]= {");
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]==arr[j])
{
printf("\"%s\",\"%s\",",arr[i],arr[j]);
}
}
}
printf("}");
}
int main()
{
char*arr[]={"Carrot","Tomato","Mustard","Carrot","Mustard","Tomato","Potato","Brinjal"};
int n=sizeof(arr)/sizeof(arr[0]);
repeating_group(arr,n);
getchar();
return 0;
}
The problem here is that it only prints the stuff that is needed but do not return an array in which the elements should be stored.
printfby different code which inserts values into an array. Have you tried doing that? What was the difficulty?