Enjoy! :) Works fine.
#include <stdio.h>
#include <string.h>
int main() {
int i, j, temp_num;
int index[6];
Type: Posts; User: Adak
Enjoy! :) Works fine.
#include <stdio.h>
#include <string.h>
int main() {
int i, j, temp_num;
int index[6];
The problem that I see is that your *b[] has "ragged" amounts of char space, for each word.
So b[0] has 5 chars (4 + end of string)
but b[2] only has 2 chars in it.
So when you start sorting,...
Try it with the new sort code. (I changed it in the earlier post). Keep in mind that capital letters will always sort out lower than any lower case letters. That can throw you if you're used to case...
Selection sort is bubble sort with a slight optimization. It doesn't compare adjacent values except the first time it enters the inner for loop. It is in the same "family" of sorters as bubble sort....
Your code is for bubble sort, and this is selection sort. Bubble sort compares only adjacent values, selection sort compares i and j indexed items, instead of i and i + 1. Bubble code might work...
You can use any sorting algorithm in conjunction with strcmp.
This is selection sort (very close to bubble sort)
char temp[MAX]; //MAX = largest element of data in array
The strings have to be differentiated before you can use strcmp(). It has to be able to find the strings before it can make any comparison.
You have several buffers (char arrays). Can't you put a...
One way would be to copy each token string into a 2D char array, one token string per row. Then sort the rows. You could do this using your buffers 2 - 5. Is that what you intended?
A rather more...
I don't see any logic for sorting, but yes, strcmp(string1, string2) is what you want. the return from strcmp() will be 0 if the strings are equal, or the open end of the <, sign, will point toward...