Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does C code pauses after i give ./a.out?
    text
    copied!<pre><code>#include&lt;stdlib.h&gt; #include&lt;stdio.h&gt; #include&lt;string.h&gt; //This program is a sorting application that reads a sequence of numbers //from a file and prints them on the screen . The reading from the file here, //is a call back function . typedef int (*CompFunc)(const char* , const char* ); typedef int (*ReadCheck)(char nullcheck); char array[100]; //Let this function be done in the library itself . It doesn't care as to //where the compare function and how is it implemented . Meaning suppose //the function wants to do sort in ascending order or in descending order //then the changes have to be done by the client code in the "COMPARE" function //who will be implementing the lib code . void ReadFile(FILE *fp,ReadCheck rc) { char a; char d[100]; int count = 0,count1=0; a=fgetc(fp); while(1 != (*rc)(a)) { if(a=='\0') { //d[count1]='\0'; strcpy(&amp;array[count],d); count=count+1; } else { d[count1]=a; count1=count1+1; } } } void Bubblesort(char* array , int size , int elem_size , CompFunc cf) { int i,j; int *temp; for( i=0;i &lt; size ;i++) { for ( j=0;j &lt; size -1 ; j++) { // make the callback to the comparision function if(1 == (*cf)(array+j*elem_size,array+ (j+1)*elem_size)) { //interchanging of elements temp = malloc(sizeof(int *) * elem_size); memcpy(temp , array+j*elem_size,elem_size); memcpy(array+j*elem_size,array+(j+1)*elem_size,elem_size); memcpy(array + (j+1)*elem_size , temp , elem_size); free(temp); } } } } //Let these functions be done at the client side int Compare(const char* el1 , const char* el2) { int element1 = *(int*)el1; int element2 = *(int*)el2; if(element1 &lt; element2 ) return -1; if(element1 &gt; element2) return 1 ; return 0; } int ReadChecked(char nullcheck) { if (nullcheck=='\n') return 1; else return 0; } int main() { FILE *fp1; int k; fp1=fopen("readdata.txt","r"); ReadFile(fp1,&amp;ReadChecked); Bubblesort((char*)array,5,sizeof(array[0]),&amp;Compare); printf("after sorting \n"); for (k=0;k&lt;5;k++) printf("%d",array[k]); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload