Hi everyone... again me... My new project is harder :)
project wants to you how many records do you want to enter (easy part) surname name years doctor and illness. then asks to you 3 choices.
1- ascend surname
2- ascend doc
3- descend year
... and I guess I cant think wright way... anyway... my questions are.....
*-I can find biggest year I can make it descending but how can I put it with other arrays together??
*- How can the project recognize which letter is first?? is it first a or b? how can I find it and again how can I write... (surname and doctors name..)
*- is that way true or am I completly wrong way??????
please help.......

#include<stdio.h>
#include<stdlib.h>
typedef struct myType{
        char sname[20];
        char name[20];
        double old;       
        char doc[20];    
        char ill;
}table;   
int main(){
int i,j,a,b,k;
double big=0;
printf("Please give the number of data records:\n");
scanf("%d",&a);
table table1[a];
printf("Please give %d patient records in the form:\n",a);
printf("sname---name---y.o.b.---doc---ill:\n");
for (i=0;i<a;i++){
scanf("%s %s %lf %s %s",
  &table1[i].sname,  
  &table1[i].name,  
  &table1[i].old,   
  &table1[i].doc,
  &table1[i].ill
  );}
printf("Please give a sort order code according to menu:\n");
printf("          Surname ascending        : 1\n");
printf("          Doctor ascending         : 2\n");
printf("          Year-of-birth descending : 3\n");
scanf("%d",&b);
while(b<=3){
switch(b){
//Surname ascending
case 1 : 
break;
//Doctor ascending
case 2 : 
break;
//Year-of-birth descending 
case 3 :
for(k=0;k<a;k++){
if(table1[k].old>=big)
big=table1[k].old;
}
break;}}
if(b>3){
printf("Just enter 1,2 or 3\n");}
 
 

system("PAUSE");
return 0;
}

input for example can be like that....
surname name year-of-birth doctor illness
Can Murat 1976 Cerrarioğlu cancer
Kaya Osman 1979 Altınel cancer
Pelin Mine 1977 Peyter osteoporosis

if we choose 3 outpu should be
Kaya Osman 1979 Altınel cancer
Pelin Mine 1977 Peyter osteoporosis
Can Murat 1976 Cerrarioğlu cancer

I can make it (descending)1979-1977-1976 but how can I write whole line.....
and if I chose 1or 2 output should be (choose=1)
Can Murat 1976 Cerrarioğlu cancer
Kaya Osman 1979 Altınel cancer
Pelin Mine 1977 Peyter osteoporosis

how can I make it c recognize that "can" should before than "kaya" ??????

last question :( I heard some bubblesort thing.. what is it.. is it suitable for me???

last question :( I heard some bubblesort thing.. what is it.. is it suitable for me???

yes jerry, it would be very suitable for you. you would enter the struct (with name, year, doctor, illness as member variables) into an array and use a bubble sort (not the best sort unless you have only a handful of records; but probably the easiest one to learn as your first sort) to sort on the required field.
note: use the strcmp function to compare strings, < or > operator would do for the year (number). try googling on "bubble sort" "C" "tutorial" and see what comes up.

ok I am on it thnx......

Anyone to help me??? I couldnt undertstand strcmp properly and I am stuck now :( I have to finish it this sunday :( please help...... I need advice :( lots of advices :(

strcmp() compares two strings and returns an integer that indicates whether string1 is less than string2, the same as string2, or greater than string2. For example

char string1[] = "John";
char string2[] = "Mary";

int n = strcmp(string1, string2);  // 0 return value means the two strings are the same

As vijayan mentioned the bubble sort is the easiest to code and use. There are hundreds of examples if you learn to use google. Just read any of these links.

ok thats what I said... in here we can find same amount of words. But I dont want to find same word.. I want to find which one is first? I mean how can program recognize the john should be before than mary?? because it starts j which is before than m(mary)

ok thats what I said... in here we can find same amount of words. But I dont want to find same word.. I want to find which one is first? I mean how can program recognize the john should be before than mary?? because it starts j which is before than m(mary)

char john[] = "john" ;
char mary[] = "mary" ;
int result = strcmp( john, mary ) ;
if( result < 0 ) cout << john << " should be before " << mary << '\n' ;
else if( result > 0 ) cout << john << " should be after " << mary << '\n' ;
else /* result == 0 */  cout << john << " compares equal to " << mary << '\n' ;

ok thats what I said... in here we can find same amount of words. But I dont want to find same word.. I want to find which one is first? I mean how can program recognize the john should be before than mary?? because it starts j which is before than m(mary)

If you only have two names then vijayan's previous answer will do. But if you have an array of names or structures then use the bubble sort previous mentioned (twice) to arrange the names in alphabetical order, then the first name in the list will be the name you will want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.