|
|
Will do. Thx,
Ralf
ralf.riedel@usm.edu
|
|
|
|
|
Is it possible for a void function that outputs characters using the cout<< extraction statement be able to put its results into a specific file via an ofstream variable, and if yes then what function should I use?
The function works this way:
void encode(QueueNode *ithNode, char charKey)
{
if (ithNode->rightCursor != NULL)
{ if (ithNode->leftCursor->value == charKey)
cout<<"1";
else
{
cout<<"0";
encode(ithNode->rightCursor,charKey);
}
}
else
cout<<"1";
}
Basically, it outputs a binary string representation of a character. What I want to do now is to transfer each of these output bits into a file with a use of an ofstream function. Any ideas on how to do this?
|
|
|
|
|
You could rewrite the function to take the ostream as an argument
void encode(QueueNode *ithNode, char charKey, ostream &os)
{
if (ithNode->rightCursor != NULL)
{ if (ithNode->leftCursor->value == charKey)
os<<"1";
else
{
os<<"0";
encode(ithNode->rightCursor,charKey, os);
}
}
else
os<<"1";
}
And call it
ofstream ofs("data.dat");
encode(..., ..., ofs);
encode(..., ..., cout);
|
|
|
|
|
Got it, thanks for the advice.
|
|
|
|
|
hi
can i make the folder which of default to any file type ...
i had idea that if possible to convert the directory to a file format which have the unique extension so that when double clicked it will ask the password ...
actually i am doing the project on the folder security
|
|
|
|
|
If you are just wanting to set security permissions on a folder, see here.
"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
|
|
|
|
|
That's pretty much how the tar format works, or any other bundling format, like zip and rar , for that matter. There's a lot of information on this if you search for it.
|
|
|
|
|
|
hi there i am working on a project and i am trying to implementing a multi linked list which nodes include more than one data and they are ordered diffrently by these keys(name,surname etc). i implemented the list and checked. so everything goes very well but after i realize that maybe i am not creating a multi linked list i know there must be more than one header node for a multi linked list and i added the nodes by name and first name correctly. so the only issue i am curious about. am i creating the multi linked list correctly or am i creating 2 different linked list.
this is the code which i pass the node as parameter to add functions;
while ( !feof(myfile) ) {
NODE* pnew_stu;
if( !(pnew_stu = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
fscanf(myfile,"%s", &(pnew_stu->first_name) );
fscanf(myfile,"%s", &(pnew_stu->last_name) );
fscanf(myfile,"%s", &(pnew_stu->email_addr) );
fscanf(myfile,"%d", &(pnew_stu->phone_num) );
fscanf(myfile,"%s", &(pnew_stu->address) );
fscanf(myfile,"%s", &(pnew_stu->city) );
fscanf(myfile,"%d", &(pnew_stu->zipcode) );
add_fn_Node(list,pnew_stu);
add_ln_Node(list,pnew_stu);
}
and this is the functions i added the node by name and first name;
void add_fn_Node(LIST* list, NODE* pnew_stu) {
NODE* temp = list->fn_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->fn_head == NULL ) {
pnew_stu->fn_next = list->fn_head;
pnew_stu->fn_pre = list->fn_head;
list->fn_head = pnew_stu;
list->fn_count = 1;
return;
}
else {
temp = list->fn_head;
if ( (strcmp( pnew_stu->first_name, temp->first_name )) <= 0 ) {
pnew_stu->fn_next = temp;
pnew_stu->fn_pre = temp->fn_pre;
temp->fn_pre = pnew_stu;
list->fn_head = pnew_stu;
list->fn_count++;
return;
}
else {
while ( temp->fn_next != NULL ) {
if ( (strcmp( pnew_stu->first_name, temp->first_name ) <= 0 ) && (strcmp( pnew_stu->first_name, temp->fn_pre->first_name) > 0)) {
pnew_stu->fn_next = temp;
pnew_stu->fn_pre = temp->fn_pre;
temp->fn_pre->fn_next = pnew_stu;
temp->fn_pre = pnew_stu;
list->fn_count++;
return;
}
temp = temp->fn_next;
}
if ( temp->fn_next == NULL ) {
temp->fn_next = pnew_stu;
pnew_stu->fn_pre = temp;
pnew_stu->fn_next = NULL;
list->fn_tail = pnew_stu;
list->fn_count++;
return;
}
}
}
}
void add_ln_Node(LIST* list, NODE* pnew_stu) {
NODE* temp = list->ln_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->ln_head == NULL ) {
pnew_stu->ln_next = list->ln_head;
pnew_stu->ln_pre = list->ln_head;
list->ln_head = pnew_stu;
list->ln_count = 1;
return;
}
else {
temp = list->ln_head;
if ( (strcmp( pnew_stu->last_name, temp->last_name )) <= 0 ) {
pnew_stu->ln_next = temp;
pnew_stu->ln_pre = temp->ln_pre;
temp->ln_pre = pnew_stu;
list->ln_head = pnew_stu;
list->ln_count++;
return;
}
else {
while ( temp->ln_next != NULL ) {
if ( (strcmp( pnew_stu->last_name, temp->last_name ) <= 0 ) && (strcmp( pnew_stu->last_name, temp->ln_pre->last_name) > 0)) {
pnew_stu->ln_next = temp;
pnew_stu->ln_pre = temp->ln_pre;
temp->ln_pre->ln_next = pnew_stu;
temp->ln_pre = pnew_stu;
list->ln_count++;
return;
}
temp = temp->ln_next;
}
if ( temp->ln_next == NULL ) {
temp->ln_next = pnew_stu;
pnew_stu->ln_pre = temp;
pnew_stu->ln_next = NULL;
list->ln_tail = pnew_stu;
list->ln_count++;
return;
}
}
}
}
|
|
|
|
|
Are you using C or C++? If the latter, simply use two std::map<const char*, Node*> s as a means to directly access a node by first name and last name respectively. std::map does the sorting for you, and you can just add all new nodes to the head instead of scanning the list. You also won't need to copy the add function for every new 'index' you want your list sorted by.
If you do C only, you still should try to separate the task of storing a list from the task of sorting a list, so you wouldn't need one set of list functions such as adding/removing for every new sorting criterion you want to introduce.
|
|
|
|
|
i am using C i am just only wondering about am i using only one list which have two headers or two lists which the first one is the copy of the other_? and i am adding a node in ascending order(i am using double pointer for print them in descending order )
|
|
|
|
|
Ah, that makes things difficult for me, as I'm not quite sure what is and is not quite possible C.
I'd say use three lists: one just for storing the nodes in an arbitrary order, and two to store your individual sortings, with nodes that only store the key you are using, plus a pointer to the appropriate node in your first list. In the case you describe you can define the node like this:
struct keynode {
const char* key;
struct NODE* node;
}
A more general version that could be used for other types of keys could be:
enum EKeytype { SKEY, IKEY, FKEY };
struct keynode {
EKeytype keytype;
union {
const char* skey;
int ikey;
float fkey;
} key;
struct NODE* node;
}
In this case you need to check for the keytype to properly compare and sort the keys.
The disadvantage of using multiple lists is that youneed to add/remove multiple nodes. The advantage is that you can easily add more sorting criterias. And the code becomes cleaner, because you can seperate the storing from the sorting.
|
|
|
|
|
well this is my structures;
typedef struct node {
int count;
int birth_date;
int zipcode;
int phone_num;
char first_name[50];
char last_name[50];
char city[50];
char address[50];
char email_addr[50];
struct node* fn_next;
struct node* fn_pre;
struct node* ln_next;
struct node* ln_pre;
struct node* birdat_next;
struct node* birdat_pre;
} NODE;
typedef struct {
int fn_count;
int ln_count;
NODE* fn_head;
NODE* ln_head;
NODE* fn_tail;
NODE* ln_tail;
}LIST;
and i am checked with printing the nodes by ascending and descending order wtih this code;
void print_fn_list(LIST* list) {
NODE* temp = list->fn_head;
NODE* reverse = list->fn_tail;
if( temp == NULL || reverse == NULL ) {
printf("THE LIST IS EMPTY!\n");
return;
}
while( temp != NULL ) {
printf("%s %10s\n", temp->first_name, temp->last_name);
temp = temp->fn_next;
}
printf("-----------------------------------\n");
while( reverse != NULL ) {
printf("%s %10s\n", reverse->first_name, reverse->last_name);
reverse = reverse->fn_pre;
}
temp = list->ln_head;
reverse = list->ln_tail;
printf("-----------------------------------\n");
if( temp == NULL || reverse == NULL ) {
printf("THE LIST IS EMPTY!\n");
return;
}
while( temp != NULL ) {
printf("%s %10s\n", temp->last_name, temp->first_name);
temp = temp->ln_next;
}
printf("-----------------------------------\n");
while( reverse != NULL ) {
printf("%s %10s\n", reverse->last_name, reverse->first_name);
reverse = reverse->ln_pre;
}
}
as you can see i use 2 headers (list->ln_head and list->fn_head). i only want know that are these 2 heads are pointing only one list, or each of them are pointing two same list but sorted in diff. ways.
|
|
|
|
|
As you use two different add functions for the two sortings, and each creates new nodes, you'll end up with two separate lists. If that was your intention you need only one next and one pre pointer for each list. If that was not your intention, then you need to create the new node outside the add function, and have the add function(s) just update the links appropriately.
|
|
|
|
|
well i create the node outside of the add functions and pass the node to these functions. in these add functions i update the links. but the main thing is which confuses me i use two add functions.(which updating the pointer of first name and second one is for last name). so if i wanna use only one list with having two different pointers(firstname pointer and lastname pointer) must i use only one add function_? or two functions. because adding one node for two different sortings in just one function will be very difficult_?. and sorry for inconvenience situtaion of my problem : ): here is the code again of my creating and calling add functions;
while ( !feof(myfile) ) {
NODE* pnew_stu;
if( !(pnew_stu = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
fscanf(myfile,"%s", &(pnew_stu->first_name) );
fscanf(myfile,"%s", &(pnew_stu->last_name) );
fscanf(myfile,"%s", &(pnew_stu->email_addr) );
fscanf(myfile,"%d", &(pnew_stu->phone_num) );
fscanf(myfile,"%s", &(pnew_stu->address) );
fscanf(myfile,"%s", &(pnew_stu->city) );
fscanf(myfile,"%d", &(pnew_stu->zipcode) );
add_fn_Node(list,pnew_stu);
add_ln_Node(list,pnew_stu);
}
and these are the adding functions
void add_fn_Node(LIST* list, NODE* pnew_stu) {
NODE* temp = list->fn_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->fn_head == NULL ) {
pnew_stu->fn_next = list->fn_head;
pnew_stu->fn_pre = list->fn_head;
list->fn_head = pnew_stu;
list->fn_count = 1;
return;
}
else {
temp = list->fn_head;
if ( (strcmp( pnew_stu->first_name, temp->first_name )) <= 0 ) {
pnew_stu->fn_next = temp;
pnew_stu->fn_pre = temp->fn_pre;
temp->fn_pre = pnew_stu;
list->fn_head = pnew_stu;
list->fn_count++;
return;
}
else {
while ( temp->fn_next != NULL ) {
if ( (strcmp( pnew_stu->first_name, temp->first_name ) <= 0 ) && (strcmp( pnew_stu->first_name, temp->fn_pre->first_name) > 0)) {
pnew_stu->fn_next = temp;
pnew_stu->fn_pre = temp->fn_pre;
temp->fn_pre->fn_next = pnew_stu;
temp->fn_pre = pnew_stu;
list->fn_count++;
return;
}
temp = temp->fn_next;
}
if ( temp->fn_next == NULL ) {
temp->fn_next = pnew_stu;
pnew_stu->fn_pre = temp;
pnew_stu->fn_next = NULL;
list->fn_tail = pnew_stu;
list->fn_count++;
return;
}
}
}
}
void add_ln_Node(LIST* list, NODE* pnew_stu) {
NODE* temp = list->ln_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->ln_head == NULL ) {
pnew_stu->ln_next = list->ln_head;
pnew_stu->ln_pre = list->ln_head;
list->ln_head = pnew_stu;
list->ln_count = 1;
return;
}
else {
temp = list->ln_head;
if ( (strcmp( pnew_stu->last_name, temp->last_name )) <= 0 ) {
pnew_stu->ln_next = temp;
pnew_stu->ln_pre = temp->ln_pre;
temp->ln_pre = pnew_stu;
list->ln_head = pnew_stu;
list->ln_count++;
return;
}
else {
while ( temp->ln_next != NULL ) {
if ( (strcmp( pnew_stu->last_name, temp->last_name ) <= 0 ) && (strcmp( pnew_stu->last_name, temp->ln_pre->last_name) > 0)) {
pnew_stu->ln_next = temp;
pnew_stu->ln_pre = temp->ln_pre;
temp->ln_pre->ln_next = pnew_stu;
temp->ln_pre = pnew_stu;
list->ln_count++;
return;
}
temp = temp->ln_next;
}
if ( temp->ln_next == NULL ) {
temp->ln_next = pnew_stu;
pnew_stu->ln_pre = temp;
pnew_stu->ln_next = NULL;
list->ln_tail = pnew_stu;
list->ln_count++;
return;
}
}
}
}
so am i not creating only one node and sending to these add functions_?. or am i creating two nodes again in functions and update them in the list_?
|
|
|
|
|
quartaela wrote:
NODE* temp = list->fn_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->ln_head == NULL ) {
...
}
else {
temp = list->ln_head;
What do you call malloc for here? I mistook this for the code that creates the node, but apparently it's just a mistake. Especially since temp gets overwritten later anyway.
So I was mistaken, there is only one list of nodes that you have. list->fn_head and list-> ln_head just point to different positions in your list.
|
|
|
|
|
so friend i know you will have a headache cause of my questions. . but i wanna ask a final question. why there aren't any differences between sending the node or its address like this;
add_fn_Node(list,&pnew_stu);
add_ln_Node(list,&pnew_stu);
and replacing every code
pnew_stu->fn_next
pnew_stu->fn_pre
with
(*pnew_stu)->fn_next
(*pnew_stu)->ln_next
and of course sorry that silly mistake of malloc
|
|
|
|
|
If you want to make these changes, you will also have to change the prototypes of the add_XY_Node() functions so they correctly reflect the type of the second parameter.
If you do that, the suggested changes should indeed work: Instead of passing the pointer you pass the address of the variable that stores the pointer, but inside the function you dereference that address again to get the original pointer. I see no reason to do that, unless you want to modify the pointer and pass that modification back to the caller.
|
|
|
|
|
thanks for your help stefan
|
|
|
|
|
At first glance, this seems to be overly complicated. I looked back through my archives and found some code I did for a doubly-linked list (that simply held an integer). The data structures were:
struct _node
{
int m_nNumber;
struct _node* m_pNext;
struct _node* m_pPrev;
};
struct _list
{
_list( void )
{
head = NULL;
tail = NULL;
}
struct _node* head;
struct _node* tail;
}; The function signatures were:
void addToFront( struct _list* pList, int nNumber );
void addToBack( struct _list* pList, int nNumber );
void addBefore( struct _list* pList, struct _node* pNode, int nNumber );
void addAfter( struct _list* pList, struct _node* pNode, int nNumber );
void insertAscending( struct _list* pList, int nNumber );
void insertDescending( struct _list* pList, int nNumber );
struct node* findNode( struct _list* pList, int nNumber ); To create a list of ascending integers, I would simply call insertAscending() , which looked like:
void insertAscending( struct _list* pList, int nNumber )
{
struct _node* pTemp = pList->head;
while (pTemp != NULL && nNumber > pTemp->m_nNumber)
pTemp = pTemp->m_pNext;
addBefore(pList, pTemp, nNumber);
}
void addBefore( struct _list* pList, struct _node* pNode, int nNumber )
{
struct _node* pTemp = new struct _node;
pTemp->m_nNumber = nNumber;
pTemp->m_pNext = pNode;
if (pNode->m_pPrev == NULL)
pList->head = pTemp;
else
pNode->m_pPrev->m_pNext = pTemp;
pTemp->m_pPrev = pNode->m_pPrev;
pNode->m_pPrev = pTemp;
} Breaking your code down into smaller, more manageable pieces will help you a lot.
"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
|
|
|
|
|
well mate i know my code is a little bit complicated but its reason is i am just in the beginning level of my project. i will make these operations at the end . anyway thanks for your suggestions
|
|
|
|
|
Hey Friends
I downloaded google chrome, clicked on download button, a eula was displayed and volla google chrome was downloaded and installed without any UAC prompt.
That's really nice , however when i create my own setup applications (with InoSetup) they display uac prompt.
If UAC prompt can be removed from setup, it would be great , is'nt it?
Any idea how google chrome setup is doing the magic?
Regards
|
|
|
|
|
For one thing. Chrome gets installed (on Win7) to C:\Users\Hans\AppData\Local\Google\Chrome. This is a user-accessible folder (unlike Program Files), so no UAC prompt.
Note: there might be other things that suppress the UAC interaction.
|
|
|
|
|
nops that does not seems correct.
the uac prompt is displayed before even the installation begins.
|
|
|
|
|