Trying qsort on K&R "The C Programming Language" -
I'm very new on this, so I compiled the page 119 (§ on main ) Trying to do 5.11) With its dependence w / I managed to get a clean build with it:
#include = n} {allocp + = n; Return allocp - n; } And return 0; } / * Reading lines: read input lines / / int readlines (four * linepits [], integer max) {int len, nlines; Four * P, line [MAXLEN]; Nlines = 0; While ((LAN = gateline (line, maxlen)) gt; 0) if (notines> = molyllines || (p = light (= lane) == faucet) return -1; other {line [lenan-1] = Delete '\ 0'; / * Newline * / strcpy (P, Line); LinePit [Enline ++] = P;} Returns Online;} / * Writing: Write Output Lines / Write Writing (Four * LinePit [], Intel Newline) printf ("% s \ n", drawing [i]) for the int ({i = 0; i & lt; iN);} zero swap (zero * v [], int I, int j) {zero * temp; temporary = v [i]; v [i] = v [j]; v [j] = Temporary;} / * QSort: sort v [left] ... v [right] in mounting order * / zero qsort (zero * v [int], int left, int correct, int (* comp) (zero *, zero ;) (Int, void left, left, right; = (I = left; i ++; i v2) returns 1; And return 0; } / * Strcmp01: Return & lt; 0 If the s & lt; T, 0 if s == t, & gt; 0 if s & gt; T * / int strcmp01 (char * s, char * t) {for (; * s == * T; S ++, T ++) if (* s == '\ 0') 0; Return * S - * T; } / * Sort input lines * / main (int argc, char * argv []) {int nlines; Int Numeric = 0; If (argc & gt; 1 & amp; amp; amp; amp; strcmp01 (argv [1], "-n") == 0) numerical = 1; If ((nlines = readlines (lineptr, MAXLINES)) = 0) {qsort (zero **) lineptr, 0, nlines-1, (int (*) (zero *, zeros *)) (numeric? Numcmp : Strcmp01)); Writing (linper, online); Return 0; } Other {printf ("sorting input is too large \ n"); Return 1; }}
But when I run it in the DOS window (win 7 for its worth), the cursor accepts several lines of key entry input, and .... And exactly what? After typing in some lines of gringing, nothing happens. I just ctrl out of it and i'm back at a command prompt.
Alternatively, I tried to create and turn on some of the rows of stuff in a test.txt file
[DIR] mybuild.exe & lt; [DIR] test.txt
This is just an error (a win 7 dialog appears that appears "mybuild.exe has stopped working"). Find it does test.txt file; It just "stops working."
What can I do to successfully run this program? (I've never been trying this just to see it run anywhere before.) Thanks, everybody for your help.
Press F6 or Ctrl + Z to end the input in the console. Your codes (stadder, ...) to your code, I found out that the program actually runs out of the heap. You might have found qsort wrong (left> = right) right;
zero qsort (zero * v [], int left, int correct, int (* comp) (zero *, zero *)) {int i , Last; Zero swap (zero * v [], int, int); Fprintf (stderr, "left% d right% d \ n", left, right); If (left> = right) right; Swap (V, left, (left + right) / 2); Final = left; For (i = left + 1; i & lt; = right; i ++) if ((* comp) (v [i], v [left]) <0 swap (v, ++ last, 1); Swap (V, left, last); Qsort (v, left, last -1, vibration); Qsort (v, previous + 1, right, vibration); }
Comments
Post a Comment