abhimanipal 91 Master Poster

In the main function when you call getData, the array m_t is not declared anywhere .Either make this array global or pass a pointer (reference to this array) to the getData function

abhimanipal 91 Master Poster

simply use the format change function in the printf like so, and you will print your numbers as binary

printf("%b", &dec)

This is wrong.

int main()
{   
    int num= 10;
    printf("%d %b %b\n",num,&num,num);   // Wrong
                  
    return 0;
}

The output for this is 10 b b
You can print a number is hexadecimal or octal by using %x and %o respectively but this logic cannot be extended for printing in binary format. In fact I do not believe %b is a legal format specifier for printf

jonsca commented: "anonymous" is just some stupid stupid stupid spammer anyway +4
abhimanipal 91 Master Poster

I guess you best bet would be to use getline

abhimanipal 91 Master Poster

What have you got so far ?

abhimanipal 91 Master Poster

SpinLock- If a process cant get a particular resource it keeps continuously checking to see when the resource becomes available. Context switch does not take place. This would be useful in cases where context switch takes much more time than the actual computation done by the process
Mutexes- If a process cant get a particular resource the process goes to sleep. When the resource becomes available the some one will awaken the process. When the process goes to sleep, context switch takes place. This mechanism is used when the cost of context switch is a less as compared to the computation done in the process

abhimanipal 91 Master Poster

The reason why you are getting endless loops is because when you re arrange the pointers, the list becomes circular( Work out your code on a piece of paper if you dont believe me) . Another solution could be to delete the node(totally disconnect it from the list) and then call an insert routine to insert the node at the correct place . I believe this approach will require slightly more code but will be simpler to implement

abhimanipal 91 Master Poster

This is what I think

When you called malloc, you called it individually on each element in the array of pointers. So extending the same logic, when you call free, you have to call it on each element in the array.
Corrections to this post are invited

abhimanipal 91 Master Poster

I dont think you code is logically correct. If I give the input as 4, the successive values of rem will be 0,0,1. But the final value in ans will just 1. So in the 2 while loop you will just get 1 as the answer.

The usual method used to convert a decimal to binary number is to store the successive numbers in a stack and then pop the stack. You can avoid the stack if you can think up of bit wise operations to store and retrieve the remainders in a 4 byte integer

abhimanipal 91 Master Poster

A simple rule of thumb is finish up all the expression to the left, then come and evaluate the expression to the right of the pointer

For examples:
v= *p++
Go left and de reference the pointer then come and increment the pointer

abhimanipal 91 Master Poster

Your syntax is correct. But your procedure is HORRIBLY wrong. In one of my earlier posts I told you to google for some specific functions. Have you done that ?

tux4life commented: Yes. +8
abhimanipal 91 Master Poster

RIP Dave..... I knew him slightly but I could tell he was a great programmer and more importantly now I know he had great spirit.
To post on this web site despite having cancer. Respect.

abhimanipal 91 Master Poster

Replace getch() with cin.get()

abhimanipal 91 Master Poster

@choragos ...
Check out the strtok function.... I think that might solve your problem....

abhimanipal 91 Master Poster

What error are you getting ?

abhimanipal 91 Master Poster

When you display your tree in line 66, is there any problem there ?

abhimanipal 91 Master Poster

Count is the number of unique random number pairs that you want to generate, j is the number of pairs that you have already generated, so that you will know when you have generated count pairs. In such a scenario why would you want to pass j as the parameter to the function, pass count instead

The code that you have posted in post 9 is logically in correct. Implement the algorithm that I have given

abhimanipal 91 Master Poster

When you are using printf statements in the sin2() function, you print one value, using the %c specifier and the other using the %d specifier .... Is there any reason for that ?

Also I am not able to clearly understand what you are trying to do. Is this the question that you want to ask ? Generate 2 random numbers. If this pair already exits, throw these 2 numbers and generate 2 new random numbers ?

If so you want code some thing of this sort

count= No of unique random number pairs)
j=0       // j will represent the number of unique pairs already generated

a= 1st random number
b= 2nd random number

while(j<count)
{
     flag=0;
     for(i=0;i<j;i++)
     {
         check if a is equal to arr1[i] and b is equal to arr2[i]. if yes set some flag=1
    } 
       if flag is not set to 1 that means the pair does not already exist store these 2 numbers in j positions of arr1 and arr2. Increment the value of j
}
abhimanipal 91 Master Poster

@thelamb, dylan9

the reason why the program blows up when you use char codes is that in the addNode function, he is comparing string by using relational operator. This is possible only only in the string class, but if we substitute the string by char array the comparison part will get shot to hell

@thelamb
dylan has posted a lot of code. For the part he/she was stuck he/she is not asking the code but just the general idea. I dont this this is the case of a typical leech who comes here with the sole purpose of getting his work done by others

abhimanipal 91 Master Poster

I think the actual error is caused by the fact that both *default message (or probably *defaultmessage )is declared as a pointer array
I guess you mean array of pointers

and you can't assign (not 100% true, but here is ok) a string.

Why is it ok here ?

This is why if you have without * it works. or is there something else you are asking??

I think the solution provided by Salem is correct

abhimanipal 91 Master Poster

I have file(.txt) that the program reads on and it outputs the words aphabetically and if the word has been seen, it adds a count to it

This is being done with which data structure ?
If you want to use the binary tree for counting the frequency of the words, you can use inorder to check if the word exists in the tree. If it does, increment the count by 1. If it does not, create a new node

abhimanipal 91 Master Poster

Do you mean access the data members of the class policeOfficer ?
You have to use the get/set methods defined in the class policeOfficer
In the main function you have used the get/ set methods in for the class Parked Car.... Use that for example

abhimanipal 91 Master Poster

If you want to pass the shift information you want to make use of the object of the class ProductionWorker. You are trying to pass shift information in the object of class Employee

abhimanipal 91 Master Poster

Dude there are many mistakes in your program

Hi.I write a program in C for my microcontroller(PIC 18F452) but
faced to a problem that related only to C language and that is;
as you can see in my Main program and the two Functions I want to
pass an array of ; " int adcvalmax[8] " which got valued in the Function;
" int CHS_Read(int adcvalmax[8]) ", between " Main " program and
Function; void Display_AdcX(int adcvalmax[8] ) for processing.
But I do not know if my "Main & Functions" are right or not?

Here are the descriptions of my Functions and Main program;

1.int CHS_Read(int adcvalmax[8]); Reading input values by analog to digital module of the PIC18F452 and save the results in the array
" adcvalmax[m] ".

2.void Display_AdcX(int adcvalmax[8] ) ;get the array
" adcvalmax[m] "and by using it display its value on LCD.

3.In the Main program I call Function; " void Display_AdcX(int adcvalmax[8] ) " as; Display_AdcX( adcvalmax[] ); .

Would you please help me and tell me if my program and functions are right or not?And what is/are wrong in my program?

Thanks,

unsigned char ch0=0,ch1=0;
int t0=0,t1=0;
char *tc;
// This is not allowed. I guess what you want to do is declare an array of 8 and initialize all the elements to 0. You want some thing of this sort int arr[8]={0,0,0,0,0,0,0,0};
int adcvalmax[8]=0;

#define stepsize  98
int  interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
   int …
WaltP commented: Such a helpful post. I was wondering why he asked for help! -2
abhimanipal 91 Master Poster

Also to run the executable you have to type
./a.out

google for the functions fread, fwrite... This will help you get started

abhimanipal 91 Master Poster

Your scanf on line 33 ..you have made a tiny mistake ...
Is this how you take an integer as input ?

abhimanipal 91 Master Poster

I dont think so ... Each file will get its own copy of the variables defined in the header file

abhimanipal 91 Master Poster

ok ! suppose i entered values for num : 2, 5 , 7, 9, 3
the program first check every value with the value inside the loop j ? which means it will check with the next value of num ?
for example,
here first value for num is 2 so the first value of num[j] would be 5 ?
am i right ?

Why dont you put printf statements in your code and find out for your self ?

abhimanipal 91 Master Poster

Hello people I have a small doubt in operator overloading
I am trying to overload the assignment operator. Here is my code for that

class rational
{
    int x;
    int y;
public:
  //All the constructos

rational operator= (rational num)
       {
         // Why do we need to return a reference 
          this->x= num.x;
          this->y= num.y;
          return *this;
       }
};

ostream& operator<<(ostream& out, rational num)
{
         out<<"X is "<<num.x<<" Y is "<<num.y<<endl;
         return out;
}

int main()
{
    rational r1,r2,r3,r4(10,20);
    r1=r2=r3=r4;
    cout<<"r1 is "<<r1;
    cout<<"r2 is "<<r2;    
    cout<<"r3 is "<<r3;
    cout<<"r4 is "<<r4;
}

I have seen this example in various websites and in all of those the assignment operator returns a reference of the object instead of just the object the object. What exactly is the reason for that ?

abhimanipal 91 Master Poster

You could save the code to a different file and try running it there ....

abhimanipal 91 Master Poster

To access the values of an array using a pointer is quite easy

int arr[]={1,2,3,4};
int* p= arr;
int i=0;

for(i=0;i<4;i++)
          printf("%d %d\n",*(p+i), p[i]);      // To ways to do the same thing

When p is actually a short form for *(p+i). Now you can use this example in your code

abhimanipal 91 Master Poster

char *default message[]="hghgghjgh"
char *message=defaultmessage
tis line showing error as
'initializing':cannot convert from 'const char[ 9] to 'char *[]'
can u help me....?

Start your own thread for your problems

abhimanipal 91 Master Poster

Your first post says that you have to use functions ... Do you know what functions are ? Post #5 contains the skeleton of a function in C++.
This link gives you another example
http://www.cplusplus.com/doc/tutorial/functions/

Now you want to move the part of code between line 22-24 in the function call. Also make the array a global variable. This will make your life easy when you are using functions

abhimanipal 91 Master Poster

Dude you got to post some more code .....
What is the structure definition ?
How exactly are you passing it ?
How are you printing it ? (The complete statement )

Since I have absolutely no clue as to what exactly is your problem, here is a shot in the dark. Maybe this will solve your problem ?
http://www.java2s.com/Code/C/Structure/Passstructintoafunction.htm

Inspite of the fact the URL says java this is a C code

abhimanipal 91 Master Poster

Is this code all there is or is there more to it

abhimanipal 91 Master Poster

Disclaimer: I have not used fseek personally on text files

C++ reference says that

When using fseek on text files with offset values other than zero or values retrieved with ftell, bear in mind that on some platforms some format transformations occur with text files which can lead to unexpected repositioning.

Ancient Dragon, if ashwini uses fseek with offset value 0, will he still get an error ?

abhimanipal 91 Master Poster

You dont need hep ... You need the program ....

abhimanipal 91 Master Poster

I thick you can use fseek.
But you have to know how many position you want to go from start/ end of file
http://www.cplusplus.com/reference/clibrary/cstdio/fseek/

abhimanipal 91 Master Poster

The way that you are inputting the data from the file is wrong. (line 53)
Check out this link. There is a method on how to read from a file as well
http://www.cplusplus.com/doc/tutorial/files/

abhimanipal 91 Master Poster

You have 2 return statements on line 46, 47. The one on line 47 will never get executed
Similarly you have a return statement on line 52. So the code from line 53 onwards cannot execute

abhimanipal 91 Master Poster

B tress are pretty common. You might want to check out suffix trees as well.

abhimanipal 91 Master Poster

What do you mean when you say "denote addition" ?
Check out strtok(), atoi() you may find it useful to extract numbers from the string

abhimanipal 91 Master Poster

Look closely into you for loop. This is the statement that you have written

total += a[MAXVALS];

What this means is that you are adding the value stored in a[100] num times. Is this what you want to do ?

abhimanipal 91 Master Poster

which one is the easiest to apply, and if you can...can help me start on the right path

I would say the first one is the easiest .... All you need is a simple for loop

abhimanipal 91 Master Poster

You cant delete an element from an array as such. So you have 2 alternatives .

1. Shift all the elements from one place to the right of the element to be deleted till the last element of the array, one place to the right.

2. Change the entry to be deleted to -1 (or any invalid number) and later when ever you are doing any processing on the array, ignore the invalid entry

Or you could use a linked list. Deleting a node is much more easier

abhimanipal 91 Master Poster

got it all sorted out...thanks for the help!

You are welcome .... Mark this thread as solved

abhimanipal 91 Master Poster

hello,
i am student and i want to know more abour binary expression tree...i hav idea about creating binary search tree ....bt v r suposed to create binary expression tree....e.g..for a+b....+
(infix/prefix/postfix) / \
a b
will u plz help me how to proceed??

Check out this link .... Maybe this will help
http://www.google.com/search?hl=&q=binary+expression+tree&sourceid=navclient-ff&rlz=1B3GGGL_enIN258IN259&ie=UTF-8&aq=0&oq=binary+expression+

If you google properly you might even find out C++ code for it

abhimanipal 91 Master Poster

Quick question.... Are you storing the information about the books in a data structure or in a file ?
The reason I ask is that you have a ofstream object in your delete file function

abhimanipal 91 Master Poster

If you want to do many things at the same time ... I would suggest you get a grip on Multi threading as well ... Might be useful

abhimanipal 91 Master Poster

Quick question, what is the relevance of the pink rows and blue rows ?

Also I am not sure I follow the explanation of the problem. Does it happen that when you display the grid the location of the mines are visible or are they hidden like the game minesweeper ?

abhimanipal 91 Master Poster

Not exactly, what I'm trying to do is create a program that based on the words that the user puts in, the program will output those same words in random order. The link you provided gave me a little insight. It has a swap/shuffle function example. The only problem, is that it is in Java..so I would need to convert it to C.

Dude I have explained you the logic .... You will have to figure out the conversion on your own