dkalita 110 Posting Pro in Training

line#14: You have never done a "new Dll11Node()" for "iterhere->_fore" and trying to access "iterhere->_fore->_back".

This is an obvious segfault.


Use gdb to debug your code if you are working on Unix/Linux. Its not that tough to catch a segfault.

dkalita 110 Posting Pro in Training

Use CODE tag and PROPER indentation.
Explain exactly what problem you are facing.

dkalita 110 Posting Pro in Training

use while(1) loop and inside the loop read one character at a time.
Break from the loop on getting something other that 0-9.
Handle the space explicitly.
If the numbers are multi-digit numbers you will have to use temp buffer to store the number till u get a space.

WaltP commented: Terrible suggestion -4
dkalita 110 Posting Pro in Training

1- Most importantly, what u are doing here is not proper quick sort. Read about it.
2- I don't understand why you have sent the array as "*v[]". Why do you think u need that. Why not just "v[]".
3- Putting function prototype inside another function. Not a great way of writing good code.
4- Why use strcmp() for character values?

5- Use <code> tags </code>

dkalita 110 Posting Pro in Training

one way is:

const char* foo = "\n1\n2\n3\n4"

another is

char* foo[] = {"1", "2", "3"}
int count = 3;
for(i=0;i<3;i++)
  printf("\n%s", foo[i]);
dkalita 110 Posting Pro in Training

This is fine as well. But you do not know the dimension of the matrix before reading the file. So how do you declare the int array to store the matrix.

if the dimension you read from the input file is say N, you can allocate memory to the matrix variable as:

int *matrix = (int *)malloc(N*N*sizeof(int));

To access matrix[j], do:

*(matrix+i*N+j)
dkalita 110 Posting Pro in Training

line# 26:
you are trying to assign an integer to a variable of type "savingsAccount". Correct this first.


Regarding the compilation:
Show me how you are trying to compile and create the executable file. Because just including a file cannot build the complete executable, you have to link the object files as well.

dkalita 110 Posting Pro in Training

you can use

scanf("%[^\n]",...);

as well to scan a whole line.

Ancient Dragon commented: good point +36
dkalita 110 Posting Pro in Training

read the information using scanf/cin and then create the command using them.

dkalita 110 Posting Pro in Training

add

#include"savingsAccount.h"

in the file "customer.h"

dkalita 110 Posting Pro in Training

you are right again.

dkalita 110 Posting Pro in Training

yes it does.

dkalita 110 Posting Pro in Training

there is nothing in the outbuffer variable.
You are modifying the variable "outs" everytime. So reset it after every itereations to "".

When you wrote

ostringstream outs(outbuffer);

the outs variable is initialised with the string in the variable "outbuffer", it does not correlate to that variable.
So reset "outs". And at the end print outs.str() instead of "outbuffer".

dkalita 110 Posting Pro in Training
typedef ListNode *ListNodePtr;

means you are making an alias for "ListNode*" as "ListNodePtr".
So when you declare avariable of type "ListNodePtr" it will mean you are declaring a variable of type "ListNode*".

ListNodePtr *sPtr;
ListNodePtr startPtr;

You will get the difference once you replace the alias name with the original data types.

ListNodePtr *sPtr = &startPtr

Expand the alias for "ListNodePtr" you will know what it is doing.

dkalita 110 Posting Pro in Training
#include<iostream>
using namespace std;
int main()
{
   int *matrix;
   int dimension;
   /*read dimension first and initialise "dimension" and then allocate apropriate memory to "matrix" and then read the matrix into this array. This can also be done inside a function which will make your code more usable*/

   /*process the matrix, better write a function and pass the matrix to it and do the processing inside that.*/

  /*write back the new matrix data into the same file. This can also be put inside a function.*/
}

This is how you can start.
Write the fileRead, matrixProcess, and fileWrite method seperately and test them thoroughly before writing the next function.

dkalita 110 Posting Pro in Training

line# 15:
This is not the way you invoke a function.
You should first know how to do that. Please read more about functions.


Some more feedbacks:

line# 22 and 26:
How do you handle the loop if the number of rectangle is variable. Better have another argument in the function which gives the number of rectangles.

line# 30 through 33:
Why are you repeating the same statements 4 times. You could have used a "for" loop here as you did before.

dkalita 110 Posting Pro in Training

you are not resetting the stringbuffer to ""(empty string) after every iterations which is the reason why it is keeping the previous values.

Reset the stringbuf at the end of every iterations then only you will get the expected outputs.

dkalita 110 Posting Pro in Training

1>c:\users\ben\documents\university work\year 2\c++\code\myc++\spritelab\asteroidsgame.cpp(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ben\documents\university work\year 2\c++\code\myc++\spritelab\asteroidsgame.cpp(17): error C2365: 'srand' : redefinition; previous definition was 'function'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdlib.h(511) : see declaration of 'srand'

Error #1:
This is coming because C++ expects the programmer to do the necessary typecast.
In you case you should have written
srand((int)time(0));

Error #2, #3:
You are calling the srand() function in global scope which is not allowed. Any statement should be enclosed inside a function (e.g inside main())
If you try to call it globally, the compiler will try to interprete as a new function declaration and srand() is already declared in "stdlib.h"

dkalita 110 Posting Pro in Training

First you must know how to retrieve the pixel data of the image.
(Please google about that, I never tried it in C/C++, but its easy to get the same in Java which I have done)

Then you have to know how to rotate an image(pixel-wise)
http://homepages.inf.ed.ac.uk/rbf/HIPR2/rotate.htm

And then you have to process the pixel data one by one to rotate it in any angle you want.

dkalita 110 Posting Pro in Training
mylinkedlist list_arr[20];

where "mylinkedlist" is the linked list class.

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

If you are talking about evaluating an expression, here is the link
http://scriptasylum.com/tutorials/infix_postfix/algorithms/postfix-evaluation/index.htm

dkalita 110 Posting Pro in Training

Adding to that.......


You can overload the operators ==, < and > for the class.

Sorry about that. I replied as though in C++.

Please ignore the post.

dkalita 110 Posting Pro in Training

Adding to that.......


You can overload the operators ==, < and > for the class.

dkalita 110 Posting Pro in Training

What is the problem ? And where ?

dkalita 110 Posting Pro in Training

Its in C itself.
It is compiled and object is created which is archived in library.

dkalita 110 Posting Pro in Training

http://www.linuxquestions.org/questions/programming-9/non-blocking-recvfrom-644930/

It seems you have to make the socket non-blocking(Read more about blocking/non-blocking socket). Follow the steps mentioned in the above link and check whether your job is done or not.

I guess you will have to use the MSG_DONTWAIT as well while calling recvfrm().
Read the behavior in the man page of recvfrm() when you set this flag.

dkalita 110 Posting Pro in Training

Why on earth do you need a second array for reversing an array...!!!

Below is a better approach to do it:

int i,j;
for(i=0, j=arr_len-1;i<j;i++, j--)/*arr_len is the len of array*/
{
    /*  swap arr[i], arr[j]  */
}
dkalita 110 Posting Pro in Training

IMP: Use Code tags.

StringTokenizer
http://www.java-samples.com/showtutorial.php?tutorialid=236

In the below code segment

if (p > 9)
    System.out.print(" " + p);
else
    System.out.print(" " + p);

What is that you are trying to achieve. (What are you doing different for the else part)

dkalita 110 Posting Pro in Training

Please use CODE tags.
Explain your problem clearly.

Your class should be defined properly, e.g.

class spiral_matrix{
  int N;
  int matrix_data[][];

  public sparse_matrix(){
    /*Constructor*/
  }
  public init_matrix(){
    /*initialize your matrix here*/
  }
  public static void main(String argv[]){
    /*...........*/
  }
/* other member methods*/
}
dkalita 110 Posting Pro in Training

any data type that you can think of.
User defined types, char, unsigned, etc., anything.....

dkalita 110 Posting Pro in Training

can you share the code segment for both the sender and receiver programs where you are making the communication, also mention which compiler you are using and which platform(windows or Linux)

dkalita 110 Posting Pro in Training

In line# 41
push(root);

Are you trying to push root. You should have done:
push(temp);

In line#50
void free(void *ptr);

What you are trying to do here. Are you trying to free the memory or you want to redefine the function free() ?

Better read about free().


Also, review your push() and pop() operation, test them independantly before using them with your logic.

dkalita 110 Posting Pro in Training

In the recvfrom() function, use "MSG_DONTWAIT" flag in the 4th argument(which is the flag) and see whether it solves your problem.


By default, the method will wait until it gets a message from the mentioned address, and your program will proceed only after that.

Read the manual for recvfrom()
http://man-wiki.net/index.php/2:recvfrom


Hope that helps.....

dkalita 110 Posting Pro in Training

can you share your sender and receiver code snippet so that we have a better idea about how you are sending the image data via a socket.

dkalita 110 Posting Pro in Training

That's upto you.
If you want to give a new name and save you can do it.

But it is better if u use the same name because, then you will be consistent with other transmission protocols(such as ftp).

dkalita 110 Posting Pro in Training

example:

file1.h

#ifndef FILE1_H
#define FILE1_H
int fun();
#endif

file1.c

#inlclude"file1.h"
int fun()
{
     printf("in fnuction");
}

file2.c

#include"file1.h"
int main()
{
   fun();
   return 0;
}

If you are using some IDE, you can directly build the project because it will do the linking for you.

If you are working in Linux/Unix, do the following:


cc -o testout file1.c file2.c

then

./testout

to run your program.

dkalita 110 Posting Pro in Training
merge_sort((byte*)&people->name,count,sizeof(struct info),charcomp);

This is not correct. Check what are the parameters you are sending.

The prototype of the function should have been something like

void merge_sort( struct info data[], int n, int (*p_cmp_f)( ) ) ;

And you should add another comparison function for comparing string.

dkalita 110 Posting Pro in Training

Hi everyone! Is there a way/command in C to find a string that is contained in a longer string?

strstr() is the answer to this problem of yours.

I'm currently developing a C program in Windows that sends requests to a machine and gets its response through socket programming. The response is an image in jpeg/jfif format. The whole response looks like the one below:

Received data is:

HTTP/1.1 200 OK
SERVER: Network Camera
Date: Thu, 01 Jan 1970 00:01:14 GMT
Content-Type: image/jpeg
Content-disposition: filename="something.jpg"
Connection: close

I want to receive the image sent to me and it should be viewable. I tried to write the whole string above into a .jpg file but no image can be seen. I'm thinking of 2 possible solutions:

1. I might need to just get the "filename=something.jpg" part and save it as a .jpg file.
2. Also from some sources I read in the past, what I need to get are the bits that compose the jpeg file itself.

Does anyone here know which option would most likely solve my problem? Answers will be greatly appreciated. Thanks!

I didn' see where you received the image. The content you mentioned above is just some text headers.

If you want to see the image, the first thing you have to do is transfer the image file through the socket.
For that, you can read the whole .jpg file into a byte array and send it via the socket from the sender.
In …

dkalita 110 Posting Pro in Training

It wont' work if you try to send the address of the head node or any other node.
The best way is to send the list data one by one through the pipe.

You can use some flag values to mark when you are done with sending the values.

If you send the address of a node and try to get the value, it won't work because then you are trying to access the memory allocated to another process.

Hope this helps.

dkalita 110 Posting Pro in Training

before solving your problem lets look at the following code snippet

int x=4;
int y=8;
float z=x/y;
cout<<z;

Can you try this code and see what output you get.

You might be expecting the output to be: 0.5 right ?

But have a second look at the code. You are dividing an integer by another integer, so the result will also be an integer. Hence the output of the above code snippet will be:
0
instead of 0.5.

I hope you got the problem with your code.
If you want to get the exact value after division, you will have to typecast at-least the number you are dividing or the divisor to float type.

Hence the above code snippet should be corrected to

int x=4;
int y=8;
float z=((float)x)/y;/*or float z=(float)x/y;*/
cout<<z;
dkalita 110 Posting Pro in Training

Hi
Can anyone help me in suggesting how to prevent "out of memory" exception in java. I am getting this exception when I load a very large data in my application and after running the application for sometime the application throws this exception. I want to know if there is any way (such as some parellel thread) that will keep a check for the maximum memory and when the application crosses some threshold (set manually) it will show some popup and exit instead of hanging the application.
Please suggest.
thanks

dkalita 110 Posting Pro in Training

Neither did you initialised i nor did you checked for the end condition.
In your case since i is not initialised which have some garbage value and you are trying to access dictionary, which obviously will give u a segfault.
Also, since you didn't put an end condition, the loop will go infinite......

Hope this helps in solving your proble.

dkalita 110 Posting Pro in Training

initialize as

union test u;
u.f = 100.23;
dkalita 110 Posting Pro in Training

in main(), do as following:

int choice = menu();/*implement menu. It should returns the user choice*/
switch(choice)
{
   case 1:
          fun1();/*your fun*/
          break;
   case 2:
          fun2();/*your fun*/
          break;
    /*some more cases as required*/
   default:
         /*some error message*/
}
dkalita 110 Posting Pro in Training

but my teacher wants a constructor and a destructor. So i guess i have to use pointers.

upto u.
U can keep your constructor/destructor where u might want to do something else, or yes, u can use pointers.

dkalita 110 Posting Pro in Training

how do i do this without changing it to a pointer? then i need to change all the remainder of my code and would have to use a iterator.

in that case just remove the statements in the constructor and destructor in your first approach. The constructor is automatically called when u declare the variable. And teh destructor will also be invoked when its scope is over. U dont need to worry about that.

dkalita 110 Posting Pro in Training

when u write

vector<int> pq;
vector<int> data;

the constructor gets invoke which is

vector<int>::vector();

In line #41, #42, #47, #48: what do u suppose u are doing.
Thats not the way how u invoke the constructor/destructor.

U could have done something like:

#ifndef MY_MIN_PQ_H
#define MY_MIN_PQ_H

#include <iostream>
#include <vector>
using namespace std;

class my_min_pq
{
public:
	//default constructor
	my_min_pq();

	//destructor 
	~my_min_pq();

	//insert element at end of sequence, and rearrange so minimum data at the front of array
	void enqueue(int data ,int priority);

	//removes data and priority from front of vector
	bool dequeue();

	//show structure based on priority where the smallest key is the first item outputted. 
	void show_pq_structure();

private: 
	//store priority
	vector<int> *pq;

	//store data
	vector<int> *data;

	//finds minimum priority value in array and swap positions of this priority index 
	//with the first index as well as data values
	void find_min();

};

my_min_pq::my_min_pq()
{
	pq = new vector<int>();
	data = new vector<int>();
}

my_min_pq::~my_min_pq()
{
	delete pq;
	delete data;
}
dkalita 110 Posting Pro in Training

then invoke the read() method before the loop to read the 1st 16 byte.
If u dont want to read the remaining till the end remove the while loop.
But I suppose U want to read the remaining also, then just keep them or make necessary change as u like to read.

dkalita 110 Posting Pro in Training

line #64: u are passing int * instead of int.
do as

PrintOutput(*c, *d);