Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Post your latest - can you make a simple example fail yet?

Salem 5,265 Posting Sage

> the variable m_pMatriz is double* and the GetElement and SetElement are methods for CMatrix types
But those functions take and return doubles, so there should be no problem.
They're used fine in some contexts already anyway.

I've attached your code with Set/Get used in many more places, and it compiles fine here.
The //!! comments are what my g++ compiler spotted with
$ g++ -c -W -Wall -ansi -pedantic -O2 foo.cpp

Oh, you might want to rename all your loop variables from i,j to be say r,c to denote row and column. It's not always clear whether you're accessing the correct element of the array (when you're doing it directly), and r/c would make it more readable IMO.
At least by always using the set/get functions, every access is properly range checked (as it should be).

Salem 5,265 Posting Sage

http://www.faqs.org/docs/securing/chap29sec254.html
Are you entirely sure that apache is seeing the same directory structure that you're seeing?
Which real / effective user ID's is apache running with, and do these have appropriate permissions to access the files?

Create a simple C++ program which allows you to log all this information, and send it back out as a response.
Use API calls like perror() to tell you why a file could not be accessed - like could it be found, or is it permissions?

Salem 5,265 Posting Sage

> *(m_pMatriz + k * m_nCols + k) = 1.0;
In many places in your class member functions, you have this complex row/col calculation.
In other places, you call SetElement() and GetElement()

With the exception of the Set and Get functions, nothing should be aware of how the data is actually accessed. That is, all your other member functions should use the Set and Get methods.

Which OS and compiler are you using?
For Linux, consider using 'valgrind' or 'electric fence'

#include <iostream>

int main ( ) {
  int *mem = new int[5];
  for ( int i = 0 ; i <= 5 ; i++ ) {  // oops, 1 too far
    mem[i] = 0;
  }
  delete [] mem;
  return 0;
}

$ g++ foo.cpp
$ ./a.out
*** glibc detected *** ./a.out: free(): invalid next size (fast): 0x091ed008 ***
======= Backtrace: =========
/lib/libc.so.6[0x5b4424]
/lib/libc.so.6(__libc_free+0x77)[0x5b495f]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x9a2669]
/usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0x9a26b5]
./a.out(__gxx_personality_v0+0x134)[0x80485c4]
/lib/libc.so.6(__libc_start_main+0xc6)[0x565de6]
./a.out(__gxx_personality_v0+0x51)[0x80484e1]
======= Memory map: ========
0052f000-00549000 r-xp 00000000 fd:00 5342221    /lib/ld-2.3.5.so
00549000-0054a000 r-xp 00019000 fd:00 5342221    /lib/ld-2.3.5.so
0054a000-0054b000 rwxp 0001a000 fd:00 5342221    /lib/ld-2.3.5.so
00551000-00675000 r-xp 00000000 fd:00 5342973    /lib/libc-2.3.5.so
00675000-00677000 r-xp 00124000 fd:00 5342973    /lib/libc-2.3.5.so
00677000-00679000 rwxp 00126000 fd:00 5342973    /lib/libc-2.3.5.so
00679000-0067b000 rwxp 00679000 00:00 0
0067d000-0069f000 r-xp 00000000 fd:00 5342974    /lib/libm-2.3.5.so
0069f000-006a0000 r-xp 00021000 fd:00 5342974    /lib/libm-2.3.5.so
006a0000-006a1000 rwxp 00022000 fd:00 5342974    /lib/libm-2.3.5.so
008ac000-008b5000 r-xp 00000000 fd:00 5342977    /lib/libgcc_s-4.0.0-20050520.so.1
008b5000-008b6000 rwxp 00009000 fd:00 5342977    /lib/libgcc_s-4.0.0-20050520.so.1
008b6000-008b7000 r-xp 008b6000 00:00 0
008ee000-009cd000 r-xp 00000000 fd:00 9460718    /usr/lib/libstdc++.so.6.0.4
009cd000-009d2000 rwxp 000df000 fd:00 9460718    /usr/lib/libstdc++.so.6.0.4
009d2000-009d7000 rwxp 009d2000 …
Salem 5,265 Posting Sage

Please annotate your code listing with some comment indicating

// This line causes this error
// vector<int>::vector(const int, const int, const int)'
Salem 5,265 Posting Sage

> m_nCols = NULL;
> m_nRows = NULL;
NULL typically signifies a pointer, so this is sending the wrong message to the reader
Just do

m_nCols = 0;
	m_nRows = 0;

> memset(m_pMatriz, 0.0, sizeof(long double) * m_nRows * m_nCols);
http://c-faq.com/malloc/calloc.html
Filling the memory with 0 (even though you said 0.0, this is not what you get) does not guarantee a useful floating point value.
A simple loop is enough

int lim = m_nRows * m_nCols;
for ( int i = 0 ; i < lim ; i++ ) m_pMatriz[i] = 0.0;

> I have looked arround the code and found no problems, at least for me, an inexperienced programmer
Without lots of tools, pros find this hard to do as well.
Lots of testing at all stages, and walkthroughs with the debugger help you to understand what's really happening.

Salem 5,265 Posting Sage

What does SetMaxColRow() actually do?

If you just construct and destruct this object in a test program, does it still crash?

Have you looked at what other things are doing elsewhere? Just because it crashes here doesn't mean the problem is here, when dealing with dynamic memory.

Salem 5,265 Posting Sage

Ever heard of google?
http://www.google.co.uk/search?q=malloc

Ever bothered to read threads on the same page with malloc in the title?
http://www.daniweb.com/techtalkforums/thread46636.html

Salem 5,265 Posting Sage

> Guess im lucky. I have the same warnings, but no actual compile errors.
It is very difficult for newbies to tell which warnings are important, and which can be ignored. So you should really be fixing the ones you can fix, and asking questions about those you can't understand the reason for.

Even pros should be aiming for zero warnings as well.

> I would like suggestions of better ways to store the info in the array.
Voila

void getSolution ( int which, int *solution ) {
  static int solutions[][144] = {
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, …
Salem 5,265 Posting Sage

C'mon, you could have at least posted your most recent attempt at the code
http://forums.devshed.com/c-programming-42/sorting-356010.html

This post here is nearly an hour newer than your reply to my original comments, yet it's the old code.

Salem 5,265 Posting Sage

> void main (void)
main returns an int

> int a,ab[5,2],ad[5],b;
A 2D array would be int ab[5][2]; Likewise, accessing it would be scanf("%d",&ab[a][0]);

Salem 5,265 Posting Sage

How many more ideas do you want?

You already have two perfectly feasible answers.

Or is this a game of "guess which answer the interviewer" decided was the right approach?

How about
- a solution based on sets
- a solution based on hashes
- a solution based on strings

Pick any other data structure you like which has some concept of "membership" and try that.

Salem 5,265 Posting Sage

I'd suggest you get a 32-bit compiler, one which is compatible with your OS then.

Salem 5,265 Posting Sage

> next calloc is contiguous allocation, it tryies to allocate contiguous memory, so somtimes it is faster
malloc is also contiguous as well, and calloc is usually slower, not faster (it does more work)
calloc is nothing more than a wrapper around malloc + memset
http://c-faq.com/malloc/calloc.html

Salem 5,265 Posting Sage

Which compiler (and which version)?
Which version of windows?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp
Scroll down to "Communications Resources"

Salem 5,265 Posting Sage
int* fn0()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}

Results in
$ g++ -W -Wall -ansi -pedantic -O2 15puzzle.cpp
15puzzle.cpp: In function ‘int* fn0()’:
15puzzle.cpp:278: warning: address of local variable ‘solution’ returned
For every function down to fnX()
When the function exits, the array no longer exists, so your pointer is invalid.
If it works for you, it is nothing more than luck - all I get is a segmentation fault.

Also, I get
15puzzle.cpp: At global scope:
15puzzle.cpp:723: warning: unused parameter ‘nNumberofArgs’
15puzzle.cpp:723: warning: unused parameter ‘pszArgs’
If you're not going to use the parameters, then just do
int main ( )

15puzzle.cpp: In function ‘void move(int, int*)’:
15puzzle.cpp:65: warning: ‘row’ may be used uninitialized in this function
15puzzle.cpp:65: warning: ‘col’ may be used uninitialized in this function
If the uninitialised value gets used, all sorts of chaos can happen.
Ensure the variables are initialised to something sensible before trying to use them.

Two more points
1. Using goto in that manner is a very poor substitute for a while loop.
2. A consistent approach to indentation will greatly assist you (and people who help you).

Salem 5,265 Posting Sage

new is C++

malloc and calloc are C
calloc is the same as malloc, except for it clears memory to all bits zero.

new causes constructors to be called, malloc does not.

Salem 5,265 Posting Sage

http://c-faq.com/struct/padding.html
How you specify a packed structure depends on your compiler.

Salem 5,265 Posting Sage

Reciting the simple one from K&R (in some form or other) is pretty doable in an interview context, and shows the interviewer that you know some useful bits of the language.

Writing a good malloc which has decent performance and resists fragmentation on the other hand is a much harder task.

Salem 5,265 Posting Sage

> am new in this language and ... i face this question in my interview
If knowing C is a requirement for whatever you're applying for, then you're not qualified, even if you manage to spoof the answer to this question.

You might be able to regurgitate the answer, but you still won't be able to explain it.
If the interviewer asks you what "this" does, will your answer begin with "ummmm"?

Say for argument you get this job (which you're unqualified for), are you going to be back asking people to solve your assignments as well?

Salem 5,265 Posting Sage

> 1) If we have a filed in the struct which his value is known to us
Seems good to me - no extra storage needed, like working out how to allocate a big enough array of pointers. Also, checking time increases with the length of the list.

Call the new member say bool seen;

while ( node && !node->seen ) {
  node->seen = true;
  node = node->next;
}
if ( node ) {
  // I'm the start of the loop
}
Salem 5,265 Posting Sage

> double variable[1000][1000] = { 0 };
In other words, about 8MB in size.
You're basically blowing away the stack, which depending on your machine could be as little as say 16K in size.

Depending on your compiler, you can specify the initial stack size as being something else.

Since 300*300*8 is about .75 Meg, I'd guess your stack size defaults to 1MB.

1. Make it global - move the array outside of the function it is in.

2. Make it static, as in static double variable[1000][1000] = { 0 }; 3. Allocate it dynamically.

double (*variable)[1000] = new double[1000][1000]; // c++ way
double (*variable)[1000] = malloc ( 1000 * sizeof(*variable) );  // C way
Salem 5,265 Posting Sage

> linklist=(list *)malloc(sizeof(list));
This is a C program, and you're casting the result of malloc.
You don't need to do this in C.
See
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351

> scanf("%d",linklist->data);
1. You forgot the &
2. it's %c for reading chars, %d is for ints

> p1=(list *)malloc(sizeof(list));
On the last iteration of the loop, your node remains uninitialised.

Salem 5,265 Posting Sage

Well it's specific to win32 windows machines.

A near equivalent for say unix would be unistd.h

Other operating systems have their own header files.

Salem 5,265 Posting Sage

Because windows.h isn't part of either standard.

The standards committees can only decide what the standard header files should be called.

Salem 5,265 Posting Sage

> i have tiff, but there is several ways to convert on bmp so any suggestions? code snippets?
Yet this seems like such a minor issue compared to the other problem you have of recognising blocks of text, and telling them apart from other marks on the image.

I guess that will be the next question then...

Salem 5,265 Posting Sage

You normally have to type in

./program_name

Rather than
program_name

For security reasons, most people avoid having "." on their PATH.

Salem 5,265 Posting Sage

> Aug 9th 2004, 12:27 PM
You should have waited the full two YEARS before bumping this thread :rolleyes:

Salem 5,265 Posting Sage

> So is there no way other than for(i = 0; i < 50; ++i)? Come on man! There has to be a better way
yes, you code something which works on either absolute or relative errors, which we're now getting pretty fed up of telling you about.

> Besides the warning for floating point equality is there because you made the compiler to throw that warning
Do you imagine that compiler writers just throw these things in for fun, or because there is a real problem which needs to be addressed?

The lack of a warning from the compiler does not constitute a proof of correctness on your part.

> Even now I feel -ffloat-store should have been activated by default.
Erm, read the help for that flag - it serves no purpose unless you specifically rely on a particular FP behaviour (like you do).
Better written code wouldn't give a toss about the extra precision, and would get a performance benefit by not being always forced into load-store operations just for your benefit.

> have to understand all the nitty gritty internal details of the compiler
WRONG!!!!!
You need a better understanding of the language, not the implementation.

Knowing how the foo compiler implements it will not help you at all with understanding the bar compiler.

Knowing the standard inside out is what allows you to write portable code, not the grubby details of a specific …

Salem 5,265 Posting Sage

I don't know why you edited the file when the #ifdef was there just to make it so you didn't need to edit it :shrug:

Anyway, I'm now seeing the same problem on cygwin as well - which I suppose is progress in itself.

Here's my modified code - it's the same with a bit of extra debug on the end

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
  double x0,x1,a;
  int i;

  x1 = 1;
  x0  = 0;
  printf("Find square root of: ");
  fflush(stdout);
  scanf("%lf",&a);
  for(i = 0; i < 100 && x0 != x1; ++i)
  {
    x0 = x1;
    x1 = .5 * (x1 + a / x1);
#ifdef INCLUDE_PRINTF
    printf("Iteration %d - converging to %f - prev value %f\n",i,x1,x0);
#endif
  }

  printf("Finished in %d iterations\n",i);
  printf("Results: %.15f, %.15f\n",x0,x1);
  {
    union { double a; unsigned long b[2]; } v;
    v.a = x0;
    printf( "X0 in binary = %lu %lu\n", v.b[0], v.b[1] );
    v.a = x1;
    printf( "X1 in binary = %lu %lu\n", v.b[0], v.b[1] );
  }
  return 0;
}

Here are my results - the last two are the more interesting ones

$ gcc -W -Wall -ansi -pedantic -O2 -DINCLUDE_PRINTF foo.c
$ ./a.exe
Find square root of: 5
Iteration 0 - converging to 3.000000 - prev value 1.000000
Iteration 1 - converging to 2.333333 - prev value 3.000000
Iteration 2 - converging to 2.238095 - prev value 2.333333
Iteration 3 - converging to 2.236069 - prev value 2.238095
Iteration 4 - converging to 2.236068 - prev value …
Asif_NSU commented: That was really helpfull - Asif_NSU +3
Salem 5,265 Posting Sage

Have you figured out how to sort a 1-D array using your own comparison function, and the standard library qsort() function?

It's exactly the same method, the only trick is getting the compare function declared properly.

Salem 5,265 Posting Sage

Can't you find a better way of conveying your results other than some bloated shockwave flash file, which by the way I've no intention of running while I'm at work.

Does the enhanced exit condition in my example code loop forever on your machine as well?

Salem 5,265 Posting Sage

If you couldn't turn this code you had

for (int i=0; i < MAX_NUM_INTEGERS; i++){
        if (integers[i]> largest){
        largest = integers[i];
        }

Into this code you wanted

for (int i=0; i < MAX_NUM_INTEGERS; i++){
        cin >> integers[i];
        }

Then I think you need to reappraise your ambitions of being a programmer.

Salem 5,265 Posting Sage

Mmm, how about

tree= malloc(sizeof(*tree));

And
printf( "%d\n", tree->value );

Salem 5,265 Posting Sage

> here it says there is syntax error
Because due to your poor indentation, the return statement is actually outside the function.

> tree= (node*)malloc(sizeof(node *));
1. Don't cast the result of malloc in C
2. you have the wrong sizeof - it's the size of the object, not the size of the pointer you want.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351

> printf(tree->value);
You really need a better compiler if you didn't get a warning from this use of printf.
http://en.wikipedia.org/wiki/Format_string_attack

Salem 5,265 Posting Sage

> how can i loop it so it can read 10 integers?
In pretty much the same way that you loop to compare them

Salem 5,265 Posting Sage

Just for you, I downloaded and installed Mingw.

Guess what - nothing unusual happening here either, despite your broken code.

Anyway, I've cleaned it up a bit (stop it looping forever for example) and shown an example session - I suggest you do the same for a problem case as Narue suggests.

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	double x0,x1,a;
	int i;	

	x1 = 1;
	x0  = 0;
	printf("Find square root of: ");
	fflush(stdout);
	scanf("%lf",&a);
	for(i = 0; i < 100 && x0 != x1; ++i)
	{
		x0 = x1;
		x1 = .5 * (x1 + a / x1);
#ifdef INCLUDE_PRINTF
		printf("Iteration %d - converging to %f - prev value %f\n",i,x1,x0);
#endif
	}
	
	printf("Finished in %d iterations\n",i);			
	return 0;
}


$ gcc -v
Reading specs from c:/mingw/bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
$ gcc -W -Wall -ansi -pedantic -O2 -DINCLUDE_PRINTF prog.c
$ ./a.exe 
Find square root of: 5.7
Iteration 0 - converging to 3.350000 - prev value 1.000000
Iteration 1 - converging to 2.525746 - prev value 3.350000
Iteration 2 - converging to 2.391253 - prev value 2.525746
Iteration 3 - converging to 2.387470 - prev value 2.391253
Iteration 4 - converging to 2.387467 - prev value 2.387470
Iteration 5 - converging to 2.387467 - prev value 2.387467
Iteration 6 - converging to 2.387467 - prev value 2.387467
Finished in 7 iterations

My …

Salem 5,265 Posting Sage

It's wanting the equivalent of

BST_Node* temp = subRoot->getLeft();
insert(temp, key.data);

But that would be wrong as well since the pointer which gets updated by the insert() call would be that temp variable, not the left pointer in another instance of a BST_Node.


Perhaps make getLeft() return a reference rather than a pointer?

Salem 5,265 Posting Sage

> int integers[0];
Use your constant to set the maximum number of elements in the array

> int largest = integers[0];
You can only do this after you've read in some values....

> cin >> integers
Your search loop is good.
But this too needs to be in a loop if you want to read in 10 values.

Salem 5,265 Posting Sage

> A reference that is not to 'const' cannot be bound to a non-lvalue
> insert(subRoot->getLeft(), key.data);
At this point, there is no storage location (an l-value) which to take a reference to. All you have is the value (r-value) of the result of subRoot->getLeft()

I would suggest you look into how you pass things around by value or by reference.

Also
> this->data = new char[strlen(data)];
You forgot to allocate space for the \0.
Why not use std::string instead?

> return -1 == strcmp(this->data,key.data);
The standard only requires that strmp() return <0, ==0 and >0
Assuming that it's always -1, 0 and +1 is wrong.

Salem 5,265 Posting Sage

> I said so because some of you might jump into the conclusion that checking for
> inequality between two double datatypes is what's wrong with my code.
http://docs.sun.com/source/806-3568/ncg_goldberg.html
http://c-faq.com/fp/fpequal.html
Just because you believe that it "isn't a problem for me" doesn't mean that it isn't a problem. The fact that it works for you sometimes, with some compilers doesn't mean that there isn't a problem.

> it could very well be for a bug with the version of gcc I have.
Statements like this require huge amounts of proof - you don't have that.
Did you disassemble all the generated code to find out what the compiler really did?
Besides, if you did, you should have visited
http://www.mingw.org/bugs.shtml

Not to mention

$ gcc -W -Wall -ansi -pedantic -O2 foo.c
foo.c: In function ‘main’:
foo.c:16: warning: ISO C90 does not support the ‘%lf’ printf format
foo.c:16: warning: ISO C90 does not support the ‘%lf’ printf format

Read
http://www.mingw.org/mingwfaq.shtml
"MinGW uses the Microsoft runtime libraries, distributed with the Windows operating system"
It does not use the standard GNU LibC implementation, but inherits all the bugs and features of the host libraries.
Maybe by feeding printf() bogus format sequences it's corrupting the stack and the rest of your local variables into the bargain.
Do you still see a problem when you use correct printf format controls?

> Do you have the …

Salem 5,265 Posting Sage

You really need to discover the magic of
a) indentation
b) functions.

A 800+ lines of code in main(), c'mon be serious.
Nobody is going to wade through that lot just to spot what might be wrong.

A rough rule of thumb - if you can't see the entire function on screen at the same time (from it's opening brace to it's closing brace), then it's probably too big to manage.

I bet all those header files have code inside them as well right?

How about a separate function for each top-level menu choice.

>> snipped from the code...

float edit_instrument1[5]; //edit the instrument for a note
  Instrmnt *instrument1 = 0; // This variable will hold the instrument information
  // snip
  float edit_instrument2[5]; //edit the instrument for a note
  Instrmnt *instrument2 = 0; // This variable will hold the instrument information

Why isn't this screaming at you to be
a) a struct containing several things
b) an array of that struct.
That would cut down significantly on the number of variables you have.

Salem 5,265 Posting Sage

> I know about the issues involving comparison of double datatypes
"This is a hole, and I know I'm lying at the bottom of it."
What exactly were you expecting to happen?
If you know about the issues, why didn't you code around them and test on each compiler?

> The problem is if compiled with compilers other than gcc (I have tested it with lcc, visual C++ and borland C++
Proving that your code has undefined behaviour.

> but in this particular case it is guaranteed that x1 will stop changing after certain iterations.
Just because the printf outputs "1.234" and "1.234" does not mean the equivalent numeric test for inequality will fail. Printing things to only 6 digits of precision when doubles have 15 digits of precision is going to entail a certain amount of rounding.

> Uncomment the printf statement within the loop. And you will see everything works fine.
Try printing out the value of i at the end of the loop.
Without printf slowing it down, it's probably executing many 1000's more iterations. Which might mean it eventually stumbles upon convergence.

Adding a final "\n" to your printf would be a good idea as well.

Salem 5,265 Posting Sage

> for( i = 0, j = 5; i<5; i++,j--)
The last element of the array is at index 4, not index 5

for ( i = 0 ; i < 5 ; i++ ) // going forwards
for ( i = 4 ; i >= 0 ; i-- ) // going backwards

Salem 5,265 Posting Sage

> looking at ur requierment, u can write in swap funtion like
What is wrong with using a temporary variable?

Not to mention the possibility of data corruption due to whatever way you machine handles arithmetic overflow and underflow.

Salem 5,265 Posting Sage

> I want to do the following things in a single program
http://www.daniweb.com/techtalkforums/announcement8-2.html

> Help required
Did you think of that topic all by yourself?

> This very urgent .please help me immediatly.
http://www.catb.org/~esr/faqs/smart-questions.html#urgent

Salem 5,265 Posting Sage

> Please help me. It's urgent....
http://www.catb.org/~esr/faqs/smart-questions.html#urgent

http://www.daniweb.com/techtalkforums/thread29300.html
Dredging up long dead threads with pointless "me too" queries won't buy you much sympathy either.

Salem 5,265 Posting Sage

There seems to be something wrong with your keyboard, the full-stop key is very sticky and appears lots of times.

Also, post some actual error messages of what you actually did.

Salem 5,265 Posting Sage

Is this in the compiler itself, or in a program you created which has compiled OK, but which crashes when you run it.