dkalita 110 Posting Pro in Training

when u create a new thread it usually cannot access the memory allotted to other process including its parent. U need to use shared memory or other IPC for communication. I may not be correct totally but this is an IPC issue. Read on how to communicate between diferent processes.

dkalita 110 Posting Pro in Training

u can make it as

string* Test::getNames()
{
        string *names = new string[3];   
        names[0] = "cat";
        names[1] = "dog";
        names[2] = "rat";
        return names;
}

/*and in main*/
int main()
{
   Test t;
   string *names;
   names = t.getNames();
   cout<<names[0];
   cout<<names[1];
   cout<<names[2];
   return 0;
}
dkalita 110 Posting Pro in Training

when do u suppose the control is coming to line #25?

dkalita 110 Posting Pro in Training

Hi,

Why not make an array of strings and return to a pointer.


So rather you have

string * Test::getNames(string[] names)
{
    string y[0] = "dog";
    string y[1] = "happy";
    string y[2] = "night";"
     return y; 
}

that might work.

Incorrect syntax.

When u write string y[0] it declares an array of string with 0 elements and if u want to initialize them write

string y[] = {"dog", "cat"};
dkalita 110 Posting Pro in Training

u will get the result by that approach also. But I would suggest u to compare the characters at the first half withe second character by character.

dkalita 110 Posting Pro in Training
void Test::getNames(string[] names)
{
     names[0] = "test1";
     names[1] = "test2"
     return;
}
dkalita 110 Posting Pro in Training

the buffer is not allocated with sufficient memory.

dkalita 110 Posting Pro in Training

line #11: u are calling fun1 and expecting the ret val of fun3
line #19: u are calling fun1 and expecting the ret val of fun2

dkalita 110 Posting Pro in Training

1> read an item
2> start from the begining of your list:
if(new item > curent node item)
move to next node
else
break
3> create a new node with the new data
4> put the new node in the current location.:
*** for this u have to keep the previous node address in some temp variable.

start coding.............

dkalita 110 Posting Pro in Training

line #224:
U are getting the max node in the temp variable. But u have not put it in the particular location. No links assigned. !!!!!!!!!

* Instead of deleting the cur node, copy the maxnode data into cur node and delete the max node.

There may somemore error I dint checked all your code.

dkalita 110 Posting Pro in Training
int main()
{
    float judge_score[5][5];/*array for storing the scores*/
    float judge_avg[5];/*array for storing averages*/

    int i, j;
    float sum, total = 0;
    /*Read judge score and calc avg*/
    for(i=0;i<5;i++)/*for 5 judge*/
   {
       //FOR JUDGE i
      cout<<"\nJudge:"<<i<<" enter scores:";
      sum = 0.0;
      for(j=0;j<5;j++)/*for 5 scores of each judge*/
      {
           cin>>judge_score[i][j];   //j'th score of judge i
           sum = sum+judge_score[i][j];
      }
      //calculate avg for judge i
      judge_avg[i] = sum/5.0;
      total = total + judge_avg[i];
   }
   cout<<"Total score:"<< total;
   return 0;
}
dkalita 110 Posting Pro in Training

that is not a way how u should proceed declaring so many variables with similar meaning.
This is where people uses array.
Use a 2D float array to store your scores. Use another array for storing the averages.

e.g.

float judge_score[5][5];
float judge_avg[5];
dkalita 110 Posting Pro in Training

good catch....

dkalita 110 Posting Pro in Training

The error u are getting is clear enough to know whats wrong. I didn't checked that before.

U are passing improper parameters to the Carbol2::gamber() function.
The expected param is an object of type Carbol2 but u are passing something else.

Change the protocol of the gamber method in Carbol2 so that it takes the parameter u want to pass.

dkalita 110 Posting Pro in Training

add the default constuctor in Carbol class.
Check the line:

Carbol2 ubjuct;

when u do this it invokes the default constructor of Carbol2 which is Carbol2::Carbol2()
and also the default constructor to the base class is invoked which does not exist.
You have to write the default constructor for the base class i.e. Carbol.
In Carbol class just add:

Carbol(){}

in the public scope.

cheers...

dkalita 110 Posting Pro in Training

in class AVLTree:
You are not initializing root.
Add a constructor and initialize the root with NULL in there.

AVLTree()
{
    root = NULL;
}
dkalita 110 Posting Pro in Training

U are making a shallow copy for Message while assigning it to the data.
U need to do a deep copy instead to retain the member data.
Overload the assignment operator for Message class and use strcpy() in it for copying each of the member.

There may be some more problems. But resolve this issue first.

dkalita 110 Posting Pro in Training

line 18: use the commented statement at line #15.
remove the semicolon at its end.
line #21: u are returning 0 on success. (0 is generally used as false)

dkalita 110 Posting Pro in Training

include stdbool.h

The type is "bool"

e.g.

#include<stdbool.h>

bool b= true;

this works in my compiler(cc).

Iam3R commented: Thanks +1
dkalita 110 Posting Pro in Training

its because in line #7 u are reading using scanf() and its looking for an int as input. When u enter a non-digit character it doesn't get what it is expecting hence it won't set the value to the variable num.
Try giving a character in the very first time and u will see the difference. It will go to the default clause of the switch statement.

dkalita 110 Posting Pro in Training

when accesing at an index say
kind.at(n)
just make sure that n>=0 and n<kind.size()

e.g. check in lines 85, 87, 88, 91, 118.
I didn't checked it completely, do it yourself.

dkalita 110 Posting Pro in Training

what if node==NULL and
U are trying to access node->first i.e. member of an object that doesn't exist.
This will result in seg fault.

dkalita 110 Posting Pro in Training

everywhere u are accesing the members of some structure using pointer and there doesn't seem to be any check for NULL statemnt.

dkalita 110 Posting Pro in Training
int main()
{
    int two_d[10][20];
    return 0;
}

take it....

or else tell us what problem u are facing with 2d array.....

dkalita 110 Posting Pro in Training

1> use code tag

2> in function square_array() and cube_array() u are modifying the original array loosing the original values.

dkalita 110 Posting Pro in Training

tower of hanoi is a very good example for solving by recusrion.

Though recusrion is helpful at times while solving some very critical problems though it has some demerits. Read about recursion in more detail to know its merit and demerits.

dkalita 110 Posting Pro in Training

> line #4:Start using int main() instead of void main().
> line #25: when u reach the end, say i=3 and length of string is 4, u are accessing the (i+1)th element that is arr[4] which does not exist because your string ends at index 3. Try to correct it.
> your logic won't give u waht u are trying. Check it agin.

> if the input to your logic is "a-dgh" the output according to your problem definition should be "a-dgh" only but if u try to get the original string back u would end up with getting: "abcdgh". Note that.

> here is what u can try to achieve your task.

void compress(char* input)
{
        if(input==NULL)
                return;
        int ilen = strlen(input);
        if(ilen<3)
                return;
        int i=1, j=0;
        char* result = (char*)malloc(ilen+1);

        int seq_start_index = 0;
        while(input[i]!=0)
        {
                if(input[i]-1!=input[i-1])
                {
                        result[j++] = input[seq_start_index];/*sequence starting char*/
                        if(i-seq_start_index>2)/*if the sequence length is more than 2 add '-' and the end char*/
                        {
                                result[j++] = '-';
                                result[j++] = input[i-1];
                        }
                        else if(i-seq_start_index==2)/*if the length is 2 then dont add the '-'char*/
                                result[j++] = input[i-1];
                        seq_start_index = i;/*start a new seq*/
                }
                i++;
        }
        if(seq_start_index<i-1)/*if the seq was not processed, e.g. if input was "abdefgh", the above loop will retrieve only "ab", d-h is not yet added*/
        {
                result[j++] = input[seq_start_index];
                if(i-seq_start_index>2)
                {
                        result[j++] = '-';
                        result[j++] = input[i-1];
                }
                else if(i-seq_start_index==2)
                        result[j++] = input[i-1];
        }
        else
                result[j++] = input[seq_start_index];
        result[j] = '\0';/*string termination*/
        strcpy(input, result);
        return;
}

Go …

dkalita 110 Posting Pro in Training

u r welcome

dkalita 110 Posting Pro in Training

hey thats the Counter class. Sorry I misspelled it.
Make it as

int Counter::count = 0;
Nick Evan commented: Simple fix, problem solved! +10
dkalita 110 Posting Pro in Training

u must intialize a static member.
Add the line

int Counter::count = 0;

before main() or other module where u are using or just after declaring your class.


A static data member must always be initialized before being used.

dkalita 110 Posting Pro in Training
dkalita 110 Posting Pro in Training

line #38:
u are not using strtok() in the way u should.
If u want to continue to get the next token then u must pass NULL in the 1st argument to strtok() after making the first call to it with the actual string.

its like:

char *tok = strtok(str, " ");
//next token u can get by
tok = strtok(NULL, " ");

U are passing the input string all the time hence its giving the 1st token all the time.

read manual of strtok (type "man strtok" in linux)

Sorry I didn't checked all of your code and directly went to the problem line.
Thanks to Ancient dragon for mentioning that.

dkalita 110 Posting Pro in Training

line #38:
u are not using strtok() in the way u should.
If u want to continue to get the next token then u must pass NULL in the 1st argument to strtok() after making the first call to it with the actual string.

its like:

char *tok = strtok(str, " ");
//next token u can get by
tok = strtok(NULL, " ");

U are passing the input string all the time hence its giving the 1st token all the time.

read manual of strtok (type "man strtok" in linux)

dkalita 110 Posting Pro in Training

that is called the arrow operator which is used to access the members of a class or a struct using a pointer.
Check the link
http://iqsoft.co.in/cpa/notes-cpp/structs/arrow.html

dkalita 110 Posting Pro in Training

I still doubt your logic for solving a sudoku.
Anyways what the checkDigit() method doing?

And will u explain your logic in summary (not in codes just the summary such a pseudocode with minimum complexity).

dkalita 110 Posting Pro in Training

what kind of sorting algorithm is that.???
Read about sorting first.
U are not using a correct sorting algo.

dkalita 110 Posting Pro in Training

what is the error u are getting.
Or what is the output coming and what u expected....

dkalita 110 Posting Pro in Training

u need a heapsort.cpp file for creating heapsort.o
U are not giving input to the g++ command in line #13 in the Makefile.


If u have only a heapsort.h file where the whole thing is defined and u have included this file from driver.cpp then u can simply remove the heapsort.o from your Makefile making it look like

# Compiler variables
CCFLAGS = -ansi -Wall

# Rule to link object code files to create executable file
driver: driver.o
	g++ $(CCFLAGS) -o driver assign6.o heapsort.o #changed the target name

# Rules to compile source code files to object code
driver.o: driver.cpp heapsort.h
	g++ $(CCFLAGS) -c driver.cpp

OR if u want the heapsort.cpp file that would be better and that is the normal standard that u should follow. Anyway the above will also work but I suggest u to move the function definitions to heapsort.cpp file keeping the declaration only in heapsort.h file and then modifying the Makefile accordingly.


One more suggestion is that U can remove the -ansi option while compiling. It actually disables many of the features of the language.

dkalita 110 Posting Pro in Training

u have declared tmp as playlist whereas strcpy takes char *
make it as

char *tmp = malloc(80);

edit:
OR

make it as

char tmp[80];
dkalita 110 Posting Pro in Training

k got it what else?

I am not going to tell what your problem is. Its u who need to ask.........

dkalita 110 Posting Pro in Training
for (z = 0; z < numOfSongs; z++){				printf("%s\n%s\n%d\n", list[i].artist, list[i].title, list[i].rating);
}

u are iterating using the variable z and using i to access the list which contains numOfSongs because of the loop which u used for reading input.

NB: Better listen to peaple who are trying to help rather than just going blah blah about anything.... anything at all........

dkalita 110 Posting Pro in Training

i suppose u are not trying what I am telling u to do.

I am still saying to recheck your code.
And this time better do it before giving just a reply.
Or check whether u have posted the same code that u have in your machine.

dkalita 110 Posting Pro in Training

the loop for bubble sort is

void bubleSort(int data[], int size)
{
   for(i=0; i<size-1; i++)
   {
      for(j=0; j<size-i-1; j++)
      {
          if(data[j] < data[j+1]) 
                swap(&data[j], &data[j+1]); /*assuming swap function is there*/
      }
   }
}
dkalita 110 Posting Pro in Training

i would suggest u to check (may be u can put a printf statement to see what i contain) again for i in line #56 without making just a guess.
Just do it, u will know:
add

printf("%d", i);

before line#56

dkalita 110 Posting Pro in Training

Yea its supposed to be like that in line 56

then think about the value of "i". What should list point to?

dkalita 110 Posting Pro in Training
dkalita 110 Posting Pro in Training

check in code:
line #56:
Are u sure it should be list or something else. Check.

line #22 to #24:
Is that portion of code really swapping the whole song or just the title......!!!.... correct it.

dkalita 110 Posting Pro in Training

would u put some light on what is the exact problem u r facing.....

dkalita 110 Posting Pro in Training

ofcourse it wil crash because it is getting into an infinite loop because its not reaching the final condition.

make your condition from if(n==0) to if(n<1) in the factorial function

dkalita 110 Posting Pro in Training

go ahead.
U are in the right direction.