I wrote and ran this code to practice the basic algorithm. but this program operation is stopped. What is the problem?  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;  int bans(const void *a, const void *b) {     return (*(int *)a - *(int *)b); }  int main()  {      int m, i;     int* arr;     scanf("%d", &amp;m);     arr = (int*)malloc(sizeof(int) * m);     for (i = 0; i &lt; m; i++) {         scanf("%d", arr[i]);     }     int n = sizeof(arr)/sizeof(arr[0]);     for (i = 0; i &lt; n; i++) printf("%d ", arr[i]);     qsort(arr, n, sizeof(arr[0]), bans);     for (i = 0; i &lt; n; i++) printf("%d ", arr[i]);     free(arr);     return 0; }
680
First off, here is some code:  int main()  {     int days[] = {1,2,3,4,5};     int *ptr = days;     printf("%u\n", sizeof(days));     printf("%u\n", sizeof(ptr));      return 0; }   Is there a way to find out the size of the array that ptr is pointing to (instead of just giving its size, which is four bytes on a 32-bit system)?
1730
I'm working in C, and I have to concatenate a few things.  Right now I have this:  message = strcat("TEXT ", var);  message2 = strcat(strcat("TEXT ", foo), strcat(" TEXT ", bar));   Now if you have experience in C I'm sure you realize that this gives you a segmentation fault when you try to run it. So how do I work around that?
99037
I see this from time to time and want to know what it is. I did try google, but its filtering out the characters from the search. I have a few books that don't reference it either.   FWIW, I remember in pascal that is was the assignment operator.   Can anybody point me to the MSDN or similar page?
109593
Let's assume process runs in ulimited environment :  ( ulimit  ... -v ... -t ... -x 0 ... ./program )   Program is terminated.  There might be many reasons : memory/time/file limit exceeded ; just simple segfault ; or even normal termination with return code 0.  How to check what was the reason of program termination, without modifying program?  P.S. I mean "when binary is given". Maybe some wrapper (ptrace-ing etc) might help?
106262
Question (since closed and deleted): . I know about the  of VLQ flags, and I can't fathom why anyone would think that question wouldn't be a candidate for removal.  Question text, for posterity:     Hey I want a Cyrus beck line algorithm program in c or c++. I have   searched a lot but hadn't got anything over Web..!!      If anyone of you have Program please give it to me and help me out.      Thank you in advance :)   I find  not compelling because it requires me to accept the premise that this question was not "unlikely to be salvageable".
117410
In Linux environment, when getting "glibc detected *** free(): invalid pointer" errors, how do I identify which line of code is causing it?  Is there a way to force an abort? I recall there being an ENV var to control this?  How to set a breakpoint in gdb for the glibc error?
22859
I read on here of an exercise in interviews known as validating a binary search tree.  How exactly does this work? What would one be looking for in validating a binary search tree? I have written a basic search tree, but never heard of this concept.
26327
What is the easiest way to handle huge numbers in C? I need to store values in the Area 1000^900, or in more human readable form 10^2700. Does anybody know of an easy way to do that? Any help would really be appreciated!
24989
I am sorry...as there are too many articles about it.But I can't simple get this.  I am confused in the implementation of AI. I have generated all possible moves of computer's type pieces. Now I can't decide the flow. Whether I need to start a loop for the possible moves of each piece and assign score to it.... or something else is to be done.  Kindly tell me the proper flow/algorithm for this. Thanks    UPDATE:    Now I coded the algorithm but not getting correct moves. Please help me find out the logical error.
108260
So I have been tasked to make an array without duplicated values from another existing array. So I did it, but I want to know is there some other better way to do that. Example input/output: Input: 10, 15, 10, 5, 1, 3 Output: 10, 15, 5, 1, 3 So here is my code. #include &lt;stdio.h&gt;  int main(void) {   const int MAX_ARRAY_SIZE = 5;    int m[MAX_ARRAY_SIZE], p[MAX_ARRAY_SIZE];     for(int i = 0; i &lt; MAX_ARRAY_SIZE; i++) {     printf(&quot;Enter number: &quot;);     scanf(&quot;%d&quot;,&amp;m[i]);   }   int k = 0;   int dup = 0;   for(int i =0; i &lt; MAX_ARRAY_SIZE; i++) {     for(int j = i +1; j &lt;MAX_ARRAY_SIZE; j++) {         if(m[i] == m[j]) {             dup = 1;         }     }     if(dup != 1) {       p[k++] = m[i];     }     dup = 0;   }    printf(&quot;The new array without repeated values\n&quot;);   for(int i = 0; i &lt; k; i++) {     printf(&quot;%d\n&quot;,p[i]);   }    return 0; }  I'm not sure if this is the right and simple way I do that. I want some suggestions. Thanks in advance. :)
46811
Is there any gcc option I can set that will give me the line number of the segmentation fault?  I know I can:   Debug line by line Put printfs in the code to narrow down.   Edits:   bt / where on gdb give No stack.
122512
In the code below  For i = LBound(arr) To UBound(arr)   What is the point in asking using LBound? Surely that is always 0.
44048
I'm working on a C-brain teaser:  Write the standard Hello-World program, without semi-colons.  My best answer so far is:  int main(void) {     if (printf("Hello World!\n"), exit(0), 0)     {         /* do nothing */     } }   But I don't understand why I don't get compiler error (Visual Studio):  error C4716: 'main' : must return a value   I've tried other functions with a return-type declared, but missing a return-statement, and get this compiler error.    Note that I've also tried:  int foo(void) {     if (printf("Hello World!\n"), exit(0), true)     {         /* do nothing */     } }  int main(void) {     foo(); }   And don't get a compiler error on foo.  If I remove the "exit(0)", I do get the compiler error.  Apparently the compiler has knowledge that "exit" is a special function?  This seems very odd to me.
4478
As Joel points out in , in  (aka: K &amp; R), there is mention of this property of arrays in C: a[5] == 5[a]  Joel says that it's because of pointer arithmetic but I still don't understand. Why does a[5] == 5[a]?
9812
How should I run another program from within my C program? I need to be able to write data into STDIN of the launched program (and maybe read from it's STDOUT)  I am not sure if this is a standard C function. I need the solution that should work under Linux.
109268
I am trying to create wrapper functions for free and malloc in C to help notify me of memory leaks. Does anyone know how to declare these functions so when I call malloc() and free() it will call my custom functions and not the standards lib functions?
20515
This question was inspired by a similar question:   My question is a little different:  Is there any way to determine the size of a C++ array programmatically?  And if not, why?  Every function I've seen that takes an array also requires an integer parameter to give it the size.  But as the linked question pointed out, delete[] must know the size of the memory to be deallocated.  Consider this C++ code:  int* arr = new int[256]; printf("Size of arr: %d\n", sizeof(arr));   This prints "Size of arr: 4", which is just the size of the pointer.  It would be nice to have some function which prints 256, but I don't think one exists in C++.  (Again, part of the question is why it doesn't exist.)  Clarification: I know that if I declared the array on the stack instead of the heap (i.e. "int arr[256];") that the sizeof operator would return 1024 (array length * sizeof(int)).