Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I use input file in gdb
    primarykey
    data
    text
    <p>I usually use an input file when I write programs so that I save myself from the hassle of entering digits again and again.</p> <p>Here is a program which I wrote for quicksort which some where is giving me segmentation fault</p> <pre><code>#include&lt;stdio.h&gt; int partition (int *,int,int); void quicksort (int *,int,int); int main() { int i,j,a[15],choice; int length; printf("Entering numbers in array \n"); for(i=0;i&lt;=14;i++) scanf("%d",&amp;a[i]); printf("the sorted array is\n"); length=sizeof(a); quicksort(a,0,length-1); for(i=0;i&lt;=14;i++) printf (" %d ",a[i]); } int partition(int *num,int p,int r) { int x,j,i,temp; x=num[r]; i=-1; for(j=0;j&lt;=r-1;j++) { if(num[j]&lt;=x) { i=i+1; temp=num[i]; num[i]=num[j]; num[j]=temp; } } num[i+1]=num[r]; return i+1; } void quicksort (int *num,int p,int r) { int q; if (p&lt;r) { q=partition(num,p,r); quicksort(num,p,q-1); quicksort(num,q+1,r); } } </code></pre> <p>and here is my input file input.txt</p> <pre><code>43 12 90 3 49 108 65 21 9 8 0 71 66 81 </code></pre> <p>when I I compile it as follows</p> <pre><code>cc quicksort.c ./a.out &lt; input.txt </code></pre> <p>Now the output I am getting is </p> <pre><code>Entering numbers in array the sorted array is Segmentation fault </code></pre> <p>What I want to know is I use gdb frequently to debug such problems. Is it possible that in gdb I take the input from the same file input.txt</p> <p>my set of commands to use gdb is </p> <pre><code>cc -g quicksort.c gdb GNU gdb (GDB) 7.1-ubuntu Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt; This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: &lt;http://www.gnu.org/software/gdb/bugs/&gt;. (gdb) file a.out (gdb) break quicksort.c:3 (gdb) run </code></pre> <p>Now what I want to know is how do I use the input file in gdb so that I do not enter again and again the array which I want to enter?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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