|
Process A launches process B with re-directed out, and err.
Process B must write to the console only - no re-direction (as the output will obviously be routed back to Process A).
I have tried a number of ways; including _cputs() etc. But I need a method where the output is rendered faithfully - where extended ASCII chars are written correctly. None of the 'console only' output functions seem to support this.
Any suggestions? Third party libraries I might look at?
Thanks in advance.
|
|
|
|
|
|
Hi Hans.
Thank you for the suggestion but all of the variations of printf, cout etc .. all write to an (re-directable) output stream. I need to write the console only.
|
|
|
|
|
You might try CreateFile() with device name "CON" and dwDesiredAccess = GENERIC_WRITE.
|
|
|
|
|
Thanks Hans ..
I am going to try that!
Cheers.
|
|
|
|
|
Hans.
Thanks a lot for the CreateFile() suggestion. It works perfectly .. I am delighted. You should create a short post about CONS only output. There is lots out there about re-direction etc .. but nothing that I could find about faithful rendering of console only output. Again .. cheers.
Best regards.
James.
|
|
|
|
|
Thanks for letting me know.
For my own curiosity, can you say why you want to disallow redirection?
|
|
|
|
|
Hi Hans.
I have been writing an application for a few years now .. www.tenfiftytwo.co.uk/pipelines
It's basically a multi-stream pipelines (textual manipulation) app that will allow you to chain together pipelines to transform text/data.
I am developing a TRACE option that allows interactive user input to inspect i/o records and in order to do this each called process must share the same console. So, console prompts must be just that - no redirection back to the calling process. They need to be console only. Only the called process output should be captured by re-directed streams.
Best regards.
James.
PS. Cannot believe that I did not think of CreateFile() .. thanks again.
|
|
|
|
|
Hi!
I've to parse an XML File using Tiny XML. My XML file contents are:
<?xml version="1.0"?>
<request>
<properties name ="TicketID">T5jkbec7i2f410m</properties>
<Form1Buttons>Login,Reset,Exit</Form1Buttons>
</request>
I've to pass "TicketID" and get the result as "T5jkbec7i2f410m". Also I've to pass "Form1Buttons" and get "Login,Reset,Exit" as result.
I've used the following code:
const char* common::Parse_XML_Document(char* filename, char* tagname)
{
TiXmlDocument * tiDoc = new TiXmlDocument(filename);
TiXmlElement * tiElement = new TiXmlElement(tagname);
const char * value = new char[1024];
if(tiDoc->LoadFile())
{
value = tiElement->GetText();
}
return value;
}
But value contains only a BadPtr. How to pass the XML file name and the tag name and retrieve the value of that tag?
|
|
|
|
|
Did you try to check out TineXML's Documentation[^] yet? They even have some tutorials[^], maybe those can help you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
pix_programmer wrote: I've to parse an XML File using Tiny XML. My XML file contents are
Certainly looks like a bad way to use xml.
pix_programmer wrote: I've to pass "TicketID"
The value 'TicketID' is not an element. Instead you have an element named 'properties' which has an attribute called 'name' whose value is 'TicketID'.
pix_programmer wrote: How to pass the XML file name and the tag name and retrieve the value of that
tag?
Your code is not even logically correct. Any program must be logically correct to work.
As two examples
- you assign an array to 'value' and then immediately assign another value to it. (As a default value it might be correct but in terms of C++ it is uninitialized and probably has lifetime problems.)
- there is no relationship between tiDoc and tiElement, so there is no way the latter can ever get a value from the former.
|
|
|
|
|
Hey everybody,
I just want to know what you think of a Huffman coding implemented using two queues and a cursor instead of using a binary tree or a priority. Please feel free to post your thoughts about it or what can be done to improve its performance. Basically, the algorithm has two queues as arguments where it first reads the first one (which has to be sorted BTW),and then creates the second queue by adding the values of the two lowest nodes in the first queue. The cursors serve as pointers of each nodes in the second queue to its left and right children in the first one (it can also be reference to the previous nodes in the second one). I think with the whole process, the algorithm has an O(n) number of operations but you be the critic.
void generateHuffman(Queue& q1, Queue& q2)
{
QueueNode *leftChild, *rightChild, *tempNode;
q1.enqueue(q1.dequeue());
q2.enqueue(q1.front()+q1.back());
rightChild = q1.backNode();
q1.enqueue(q1.dequeue());
leftChild = q1.backNode();
q2.setCursor(leftChild, rightChild);
while (q1.back() <= q1.front())
{
q2.enqueue( q1.front()+q2.front() );
tempNode = q2.backNode();
q2.enqueue(q2.dequeue());
tempNode->rightCursor = q2.backNode();
q1.enqueue(q1.dequeue());
tempNode->leftCursor = q1.backNode();
while( q2.frontNode() != tempNode)
q2.enqueue(q2.dequeue());
tempNode = NULL;
}
}
#include "QueueException.h"
typedef int QueueItemType;
struct QueueNode
{
QueueItemType item;
QueueNode *leftCursor;
QueueNode *rightCursor;
QueueNode *next;
};
class Queue
{
public:
Queue();
~Queue();
bool isEmpty() const;
QueueItemType front() const throw(QueueException);
QueueItemType back() const throw(QueueException);
QueueItemType dequeue() throw(QueueException);
QueueNode *frontNode() const throw(QueueException);
QueueNode *backNode() const throw(QueueException);
void dequeue(QueueItemType& queueFront) throw(QueueException);
void enqueue(const QueueItemType& newItem) throw(QueueException);
void setCursor(QueueNode *l, QueueNode *r) throw(QueueException);
private:
QueueNode *backPtr;
QueueNode *frontPtr;
};
Hope this helps to give me some advice. Thanks
|
|
|
|
|
So what's your question/problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Actually, I have a lot of problems when dealing with this algorithm that I made.
One is that I'm not sure if this is the right way to implement Huffman coding using two queues and cursors.
Second is that this won't work unless the first queue is sorted, and I have no clue on how to sort this using an STL sort function or any other way.
Third is that the values that each node will get shall come from an array that lists all the frequency of characters in an input file. What I have right now is an array of 256 components (for all ASCIIs) that stores these frequencies in the file. I can print them out with their designated characters, but the problem comes when I try sort the array at this point which only gives me a sorted array of values (or frequencies) that have new designated characters based on their positions after the sort.
I have my source files running so far. Do you want me to post them also here?
|
|
|
|
|
Francis Paran wrote: Second is that this won't work unless the first queue is sorted, and I have no
clue on how to sort this using an STL sort function or any other way.
Using a queue from the STL, you can sort like:
bool comparater( const int& p1, const int& p2 )
{
return p1 < p2;
}
std::deque<int> q;
std::sort(q.begin(), q.end(), comparater);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
No, it's actually a queue that I made (not an STL queue or deque) where I want the STL sort function to be used for. Do you want me to declare an STL deque instance of type int or do you just want me to use that STL instead of my queue so that its elements can be sorted?
|
|
|
|
|
I know it's not what you are after, and I may be way off base here, but it seems you are making things a bit more difficult than need be. If you are simply wanting to count letter occurances, something like the following should suffice:
struct node
{
char c;
int count;
};
int comparater( const void *arg1, const void *arg2 )
{
node a = *((node *) arg1);
node b = *((node *) arg2);
return a.count - b.count;
}
void main( void )
{
node frequencies[256] = {0};
for (int x = 0; x < sizeof(frequencies) / sizeof(node); x++)
frequencies[x].c = x;
qsort(frequencies, sizeof(frequencies) / sizeof(node), sizeof(node), comparater);
std::cout << "The two letters with the highest frequency are "
<< frequencies[255].c
<< " and "
<< frequencies[254].c
<< std::endl;
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
The thing is that I get the frequencies of the correct characters like this:
#include <iostream>
#include <fstream>
using namespace std;
int size, i, j;
void count_chars( int *counts );
double frequency (int char_count, int length);
void generateHuffman(Queue& q1, Queue& q2);
int main()
{
char *stringChar;
int *counts;
ifstream infile( "project2input.txt" );
infile.seekg (0, ios::end);
int size = infile.tellg();
stringChar = new char[size];
for(i = 0; i<size; i++)
infile.seekg(i)>>stringChar[i];
infile.close();
counts = new int[256];
count_chars( counts );
cout<<"\n\n";
int newSize;
for(j = 0; j<256; j++)
if (counts[j] != 0)
{ newSize++;
cout<<(char) j<<"= "<<j<<" ("<<frequency (counts[j],
size)*100<<")\n";
}
cout<<endl<<newSize<<" characters\n";
cout<<endl;
char c;
cin>>c;
return 0;
}
void count_chars( int *counts )
{
for ( int i = 0 ; i <256 ; i++ )
counts[ i ] = 0;
ifstream file( "project2input.txt" );
if ( !file ) {
cerr <<"Couldn't open the input file!\n";
throw "abort";
}
for ( ; ; )
{
unsigned char c;
file>> c;
if ( file )
counts[ c ]++;
else
break;
}
}
It seems like the positions of the character frequencies in counts, when converted into char and once output, will always show me the characters they represent. However, the problem comes with sorting them where it changes their positions in the array as well as the characters they will now represent.
I had the sort function in <algorithm> already figured out; now it is just sorting this array using that function, but at the same time still retaining the characters being represented by their frequencies in the file.
Putting the character and its frequency into a node really looks promising to me in solving any issues of sorting. My guess would be sorting nodes based on their frequency values, but am I right at this or am I just making things more complicated and worse by adding a little more overhead?
|
|
|
|
|
The variable newSize is not ever initialized (to 0 ) so incrementing it will produce undesirable results.
Francis Paran wrote: However, the problem comes with sorting them where it changes their positions in
the array as well as the characters they will now represent.
Which is why I showed using a structure to hold the character and its frequency.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Is there any addition code which makes an application (created in VS2003 VC++ MFC) Windows 7 operating system compatible?
Please help me.
Is there different code for Windows 7 operating system 32 bit and Windows 7 operating system 64 bit?
Please help me.
|
|
|
|
|
Janaiko wrote: Is there any addition code which makes an application (created in VS2003 VC++ MFC) Windows 7 operating system compatible? Code created in VS2003 should work fine on Win 7. You might have UAC problems; google for UAC to learn more.
If you have specific problem, please post here.
|
|
|
|
|
Just about everything works fine, like Hans said, UAC might cause some problems, also if you derived some classes from MFC classes, there may be some minor issues, but overall works well.
|
|
|
|
|
If you have a program that runs for example on XP but has problems on Windows 7 you can run it in compatibility mode. See the compatibility tab in the Properties dialog. (Right click the .EXE and select Properties in Explorer.)
If you are asking if you need to change anything when moving from VS2003 to a later version of Visual Studio then you may find that you need to #define the WINVER appropriately - ie to earliest version of Window you want to be able to run on. The default value may be different if you didn't explicitly set it in your VS2003 project. You may have some problems rebuilding but you can ask here if so.
If you are talking about adding code to make use of new features in Windows 7 then you will have to find out about the features and how to implement them. There are many new features in Windows 7, eg for the new task bar. If using MFC many Windows 7 features are automatically used or implemented with a just few lines of code when you rebuild your application with VS2010.
Also re 64 bit Windows: If you write code portably then you can compile for Win32 or Win64. If Win64 is the target it will run faster under 64-bit Windows but won't run under Win32. But if you just target it for 32-bit then it can run under Win64 and Win32.
Andrew Phillips
http://www.hexedit.com
andrew @ hexedit.com
|
|
|
|
|
Is it possible to have same PnP Device ID for two USB mass storage
|
|
|
|
|
Device IDs will be unique if the vendor adds a serial number to the device ID string. I'm not sure that all vendors do that consistently.
|
|
|
|