| | |
Hospital Record.. double array.. help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 55
Reputation:
Solved Threads: 0
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.......
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.......
C Syntax (Toggle Plain Text)
#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; }
Teach me, Show me, Educate me :)
•
•
Join Date: Apr 2007
Posts: 55
Reputation:
Solved Threads: 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" ??????
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" ??????
Teach me, Show me, Educate me :)
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
•
•
•
•
last questionI heard some bubblesort thing.. what is it.. is it suitable for me???
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.
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
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.
c Syntax (Toggle Plain Text)
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.
Last edited by Ancient Dragon; Apr 20th, 2007 at 10:58 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Apr 2007
Posts: 55
Reputation:
Solved Threads: 0
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)
Last edited by jerryseinfeld; Apr 20th, 2007 at 11:09 am.
Teach me, Show me, Educate me :)
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
•
•
•
•
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)
C Syntax (Toggle Plain Text)
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' ;
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Other Threads in the C Forum
- Previous Thread: Can Templates Have prototypes ?
- Next Thread: Please help, im new at this :/
| Thread Tools | Search this Thread |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings structures systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






I heard some bubblesort thing.. what is it.. is it suitable for me??? 