|
#1
| ||||
| ||||
| 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 |
|
#2
| ||||
| ||||
| 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 |
|
#3
| ||||
| ||||
| 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 |
|
#4
| ||||
| ||||
| 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;
}
__________________ 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. |
|
#5
| ||||
| ||||
| 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 |
|
#6
| ||||
| ||||
| 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 |
![]() |
| Thread Tools | |
|
|