image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
Thread Tools
  #1  
Old November 4th, 2003, 06:48 AM
WeeZer51402's Avatar
Right 00.1% of the Time
 
Join Date: Dec 2002
Location: Lost in my own unintelligible ramblings
Posts: 473
Thanks: 0
Thanked 0 Times in 0 Posts
WeeZer51402 is on a distinguished road
Alphabetizing

Right no im working on a server that reads a database from a file into a structure, this database includes last name, first name/email/phone number, the way im going to set it up so people can add entries is by making it a linked list but then the question becomes how do i alphabetize the list by last name and how could i tell it to just search for 'a's
thanks,
mike
__________________
ON THE WAY:
15" PB 1.67|100|1024 --- 10.4
------------------------------------------
17" iMac G5 1.8|80|512|BT --- 10.3.9
FrankenMac G4 500|55|640 --- 10.3.9
PowerMac 9600 300|4|512 --- 1.2
eMachine 500is 500|4.3|196 --- OpenStep 4.2
Server 2.3|260|512 --- FedoraCore
Reply With Quote
  #2  
Old November 4th, 2003, 07:02 AM
Arden's Avatar
Where mah "any" keys at?
 
Join Date: Dec 2002
Location: San Francisco
Posts: 7,744
Thanks: 0
Thanked 0 Times in 0 Posts
Arden is on a distinguished road
Um, what language are you using?
__________________
System:
2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 200 GB hard drive, runs 10.5.5
1.6 GHz iMac G5, 1.5 GB RAM, 250 GB hard drive, runs 10.4.11 (slightly out of commission at this time)
iPhone, 4 GB, OS X 2.0.2
Reply With Quote
  #3  
Old November 4th, 2003, 09:07 AM
WeeZer51402's Avatar
Right 00.1% of the Time
 
Join Date: Dec 2002
Location: Lost in my own unintelligible ramblings
Posts: 473
Thanks: 0
Thanked 0 Times in 0 Posts
WeeZer51402 is on a distinguished road
sorry, its c...i posted that too early in the morning to remember
__________________
ON THE WAY:
15" PB 1.67|100|1024 --- 10.4
------------------------------------------
17" iMac G5 1.8|80|512|BT --- 10.3.9
FrankenMac G4 500|55|640 --- 10.3.9
PowerMac 9600 300|4|512 --- 1.2
eMachine 500is 500|4.3|196 --- OpenStep 4.2
Server 2.3|260|512 --- FedoraCore
Reply With Quote
  #4  
Old November 4th, 2003, 03:10 PM
WeeZer51402's Avatar
Right 00.1% of the Time
 
Join Date: Dec 2002
Location: Lost in my own unintelligible ramblings
Posts: 473
Thanks: 0
Thanked 0 Times in 0 Posts
WeeZer51402 is on a distinguished road
well i tried writing a bubble sort program to do it but it doesnt quite work right...

Code:
#include <stdio.h>

int main (void) 
{
    char string[6];
    int x,y,temp=0;
    
    printf("Enter 5 Letters: ");
    scanf("%s", &string);
    for(x=0; x<6; x++)
        for(y=0; y<6; y++)
            if(string[y] > string[y+1])
            {
        
            temp=string[y+1];
            string[y+1]=string[y];
            string[y]=temp;
            }
    for(x=0; x<7; x++)   
        printf("%c", string[x]);
    printf("\n");
        
    return 0;
}
Update: i fixed the program, but i would like to make that array string, dynamic so the user can input more info than just 5 chars, malloc maybe?
__________________
ON THE WAY:
15" PB 1.67|100|1024 --- 10.4
------------------------------------------
17" iMac G5 1.8|80|512|BT --- 10.3.9
FrankenMac G4 500|55|640 --- 10.3.9
PowerMac 9600 300|4|512 --- 1.2
eMachine 500is 500|4.3|196 --- OpenStep 4.2
Server 2.3|260|512 --- FedoraCore

Last edited by WeeZer51402; November 4th, 2003 at 09:01 PM.
Reply With Quote
  #5  
Old November 5th, 2003, 06:30 AM
WeeZer51402's Avatar
Right 00.1% of the Time
 
Join Date: Dec 2002
Location: Lost in my own unintelligible ramblings
Posts: 473
Thanks: 0
Thanked 0 Times in 0 Posts
WeeZer51402 is on a distinguished road
ok, i made it so you arent so limited in your input, the problem i was getting at that printf function was with the string length of 'string', there were termination characters in it, heres what does work though, get the strlength of a pointer, storing it in a variable and then copying its contents into 'string'.


Code:
#include <stdio.h>

char *str[];

int main (void) 
{
    char string[1000];
    int x,y,temp=0,i=0,a;
    printf("Enter Less Then 1001 Letters: ");
    scanf("%s", &str);
    a=strlen(str);
   
    strcpy(string, str);
    
    for(x=0; x<(a+1); x++)
        for(y=0; y<(a+1); y++)
            if(string[y] > string[y+1])
            {
                temp=string[y+1];
                string[y+1]=string[y];
                string[y]=temp;
            }
            
    for(i=0; i<(a+2); i++)
            printf("%c", string[i]);
                
    printf("\n");
        
    return 0;
}
__________________
ON THE WAY:
15" PB 1.67|100|1024 --- 10.4
------------------------------------------
17" iMac G5 1.8|80|512|BT --- 10.3.9
FrankenMac G4 500|55|640 --- 10.3.9
PowerMac 9600 300|4|512 --- 1.2
eMachine 500is 500|4.3|196 --- OpenStep 4.2
Server 2.3|260|512 --- FedoraCore
Reply With Quote
  #6  
Old November 5th, 2003, 03:59 PM
WeeZer51402's Avatar
Right 00.1% of the Time
 
Join Date: Dec 2002
Location: Lost in my own unintelligible ramblings
Posts: 473
Thanks: 0
Thanked 0 Times in 0 Posts
WeeZer51402 is on a distinguished road
any help...anybody, i need to make this dynamic, i dont want to declare 'char string[1000]', also now that i can alphabetize how do i take a file and alphabetize strings from that file? ex.

mike
bob
george
fred
charles


how could i make a program read that from a file and sort it?
__________________
ON THE WAY:
15" PB 1.67|100|1024 --- 10.4
------------------------------------------
17" iMac G5 1.8|80|512|BT --- 10.3.9
FrankenMac G4 500|55|640 --- 10.3.9
PowerMac 9600 300|4|512 --- 1.2
eMachine 500is 500|4.3|196 --- OpenStep 4.2
Server 2.3|260|512 --- FedoraCore
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 05:56 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.