Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

sorting strings function with pointers

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 3 posts
I have to write a program that takes a char pointer, scans the strings into the pointer then passes them to a function which then passes them to a string compare function. The string compare function is supposed to work like strcmp in the stings.h library. Here is the code if anybody can figure this please let me know.

#include <stdio.h>
int strcompare(char *str1, char *str2);
void stringsort(char *strings[]);
int main(){

char *strings[20];
int i;
for(i=0; i<20; i++){
scanf("%s", &strings[i]);
void stringsort(char *strings[]){
char *temp="~~~~";
char order[20][30];
int i, j, m, k;
for(j=0; j<20; j++){
for(i=0; i<20; i++){
if(strcompare(strings[i], temp)<0){
temp = strings[i];

for(m=0; m<30; m++){
order[j][m] = temp;
for(i=0; i<20; i++){
printf("%s\n", order[i]);
int strcompare(char *str1, char *str2){
int i, j, k, m, n, best;
if( str1 < str2){
for(j=0;(str2[j] = str1[j])!='\0';j++){
return -1;
if( str1== str2){
return 0;
if( str1 > str2){
return 1;
  • 0


Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP