Hi,
I made a program that lists all possible anagrams of a word.Now I'd like to include anagrams of subsets of letters in the word.I have the code for making the subsets also now.But i do not want merge them as a single code.So I'd like to know if there is a way pipe the output of one to another in VC++.They are in the same project file in VC++,if that matters.

Thanks in advance,
Prasanna.

Recommended Answers

All 2 Replies

Yes. Ensure that the code that makes the first list of words returns that list (or array) of words from a function and use it as input to the next function that will further pair-down the list.

Here is an MFC (VC++) example of a CStringArray being "piped" into multiple functions.
One function looks for the presence of the letter A and the other looks for the presence of the letter S.
The results are also "piped" into a function that displays the contents.

// DW_376060.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "DW_376060.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
CStringArray& GetListWithA(CStringArray& arr)
{
	static CStringArray arrNew;
	int iSize = arr.GetSize();

	for(int i =0; i < iSize; i++)
	{
		if(-1 != arr.ElementAt(i).FindOneOf("aA"))
		{
			arrNew.Add(arr.ElementAt(i));
		}
	}

	return arrNew;
}

CStringArray& GetListWithS(CStringArray& arr)
{
	static CStringArray arrNew;
	int iSize = arr.GetSize();

	for(int i =0; i < iSize; i++)
	{
		if(-1 != arr.ElementAt(i).FindOneOf("sS"))
		{
			arrNew.Add(arr.ElementAt(i));
		}
	}

	return arrNew;
}

void ShowList(CStringArray& arr)
{
	int iSize = arr.GetSize();
	for(int i=0; i<iSize; i++)
	{
		puts(arr.ElementAt(i));
	}
}

void main(void)
{
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		return;
	}

	// Fill a CStringArray with some data
	CStringArray arr_strData;
	arr_strData.Add("Tom");
	arr_strData.Add("Prasanna");
	arr_strData.Add("Dani");

	/////////////////////////
	// Show the entire list
	ShowList(arr_strData);
	puts("--- --- ---");

	///////////////////////////////////////////////////////
	// Show the list twice filtered; once for S then for A
	ShowList(GetListWithA(GetListWithS(arr_strData)));
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.