help!! about ADT list please

Reply

Join Date: Jul 2006
Posts: 38
Reputation: comp_sci11 is an unknown quantity at this point 
Solved Threads: 0
comp_sci11's Avatar
comp_sci11 comp_sci11 is offline Offline
Light Poster

help!! about ADT list please

 
0
  #1
Jul 13th, 2006
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. #define SIZE 21
  5. #define MAX 10
  6.  
  7. int id[MAX];
  8. int idn[MAX];
  9. char fn[MAX][SIZE];
  10. char ln[MAX][SIZE];
  11. char mi[MAX][SIZE];
  12. int q1;
  13. int q2;
  14. int q3;
  15. float ave;
  16.  
  17. int menu()
  18. { int i,s=0;
  19.  
  20. while(s<1|| s>4)
  21. {
  22. clrscr();
  23. gotoxy(5,5);
  24. printf("menu");
  25. gotoxy(5,7);
  26. printf("1.insert");
  27. gotoxy(5,9);
  28. printf("2.delete");
  29. gotoxy(5,11);
  30. printf("3.Display all");
  31. gotoxy(5,13);
  32. printf("4.Quit");
  33. gotoxy(5,15);
  34. printf("Select(1-4): ");
  35. scanf("%d",&s);
  36. }
  37. return (s);
  38. }
  39.  
  40. void insert(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2,int q3,float ave,int id[MAX])
  41. {
  42. int i,p;
  43. i=p=0;
  44. while(idn>id[i] && id[i]!=-1)
  45. i++;
  46. p=i;
  47. if(id[p]==-1)
  48. {
  49. id[p]=idn;
  50. strcpy(fn[p],fn);
  51. strcpy(ln[p],ln);
  52. strcpy(mi[p],mi);
  53. q1[p]=q1;
  54. q2[p]=q2;
  55. q3[p]=q3;
  56. ave[p]=ave;
  57. }
  58. else{
  59. for(i=end(id);i>p;i--)
  60. {
  61. id[i]=id[i-1];
  62. strcpy(fn[i],fn[i-1]);
  63. strcpy(ln[i],ln[i-1]);
  64. strcpy(mi[i],mi[i-1]);
  65. q1[i]=q1[i-1];
  66. q2[i]=q2[i-1];
  67. q3[i]=q2[i-1];
  68. ave[i]=ave[i-1];
  69. }
  70.  
  71. id[p]=idn;
  72. strcpy(fn[p],fn);
  73. strcpy(ln[p],fn);
  74. strcpy(mi[p],mi);
  75. q1[p]=q1;
  76. q2[p]=q2;
  77. q3[p]=q3;
  78. ave[p]=ave;
  79.  
  80. }
  81.  
  82. void initialize(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2,int q3,float ave,int id[MAX])
  83. {
  84. int i=0;
  85. for(i=0;i<MAX;i++)
  86. {
  87. id[i]=-1;
  88. fn[i]=-1;
  89. ln[i]=-1;
  90. mi[i]=-1;
  91. q1[i]=-1;
  92. q2[i]=-1;
  93. q3[i]=-1;
  94. ave[i]=-1;
  95. }
  96.  
  97. }
  98.  
  99. int end(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2, int q3, float ave,int id[MAX])
  100. {
  101. int i=0;
  102. while(id[i]!=-1)
  103. i++;
  104. return(i);
  105. }
  106.  
  107. void delete(int idn,char fn[MAX],char ln[MAX],char mi[2],int q1,int q2, int q3, float ave,int id[MAX])
  108. {
  109. int i,p;
  110. p=locate(idn,id);
  111.  
  112. if(p<0)
  113. {
  114. printf("record not found");
  115. getch();
  116. exit(0);
  117. }
  118. else
  119. {
  120. for(i=p;i<end(id);i++)
  121. {
  122. id[i]=id[i+1];
  123. fn[i]=fn[i+1];
  124. ln[i]=ln[i+1];
  125. mi[i]=mi[i+1];
  126. q1[i]=q1[i+1];
  127. q2[i]=q2[i+1];
  128. q3[i]=q3[i+1];
  129. }
  130. }
  131. }
  132.  
  133. int locate(int idn,char fn[SIZE],char ln[SIZE],char mi[SIZE],int q1,int q2, int q3, float ave, int id[MAX])
  134. {
  135. int i=0;
  136. while(x!=id[i] && id[i]!=-1)
  137. i++;
  138.  
  139. if(id[i]==-1)
  140. return(-1);
  141. else
  142. return(i);
  143. }
  144.  
  145. void displayall(int id[MAX])
  146. {
  147. int i;
  148. for(i=0;i<end(id);i++)
  149. {
  150. printf("\n%d %d",i+1,id[i]);
  151. getch();
  152. }
  153. }
  154.  
  155.  
  156. main()
  157. {
  158. int i;
  159. initialize(id);
  160. while(1){
  161. i=menu();
  162. switch(i){
  163. case 1: clrscr();
  164. prinf("\nInput id number: ");scanf("%d",&idnum);
  165. prinf("\nInput first name: ");scanf("%s",&fnm);
  166. prinf("\nInput last name: ");scanf("%d",&lnm);
  167. prinf("\nInput middle initial: ");scanf("%d",&min);
  168. prinf("\nInput quiz 1: ");scanf("%d",&qz1);
  169. prinf("\nInput quiz 2: ");scanf("%d",&qz2);
  170. prinf("\nInput quiz 3: ");scanf("%d",&qz3);
  171. ave=(qz1+qz2+qz3)/3.0;
  172. prinf("%d",aver);
  173. insert(idnum,fnm,lnm,min,qz1,qz2,qz3,aver,id);break;
  174. case 2:
  175. clrscr();
  176. printf("\nInput id number: ");scanf("%d",&idn);
  177. delete(idn,id)
  178. break;
  179. case 3:
  180. clrscr();displayall(id);break;
  181. case 4:
  182. exit(0);
  183. }
  184. getche();
  185. }
  186. }



Last edited by Dave Sinkula; Jul 13th, 2006 at 9:43 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 38
Reputation: comp_sci11 is an unknown quantity at this point 
Solved Threads: 0
comp_sci11's Avatar
comp_sci11 comp_sci11 is offline Offline
Light Poster

Re: help!! about ADT list please

 
0
  #2
Jul 13th, 2006
please help me!! about this code i've created!!
i really don't know what to do!!
I have so many errors some of those errors are:
1. invalid indirection in function insert
2. non portable pointer conversion in function insert
3. parameters q1,q2,q3 are not used in function insert

this program is about creating a list in which user can select in the menu to insert,delete or display all the data inputed.

the user should input the following if they want to add another in the list.
these are:

student number,last name,first name, middle name, quiz1,quiz2,quiz3,average of the quizes

these should appear
and must be in a parrallel arrays!

COULD SOMEONE HELP ME??!!!! PLS
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8,313
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 824
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: help!! about ADT list please

 
1
  #3
Jul 13th, 2006
I refuse to look at your code until you format it like a normal human being. It would also help if you'd stop acting like a wuss and ask a smart question.
In case you were wondering, yes, I do hate you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,609
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1614
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help!! about ADT list please

 
0
  #4
Jul 13th, 2006
what compiler are you using? my guess is Turbo C, but I could easily be wrong.

As for unused variables -- just delete them from the program.

>> strcpy(fn[p],fn);

fn is a character array, fn[p] is a single character somewhere in that array. strcpy() expects the first parameter to be a pointer to the destination string. Instead your program is just passing a single character.
Last edited by Ancient Dragon; Jul 13th, 2006 at 9:57 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 38
Reputation: comp_sci11 is an unknown quantity at this point 
Solved Threads: 0
comp_sci11's Avatar
comp_sci11 comp_sci11 is offline Offline
Light Poster
 
0
  #5
Jul 14th, 2006
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define SIZE 5
  4. #define MAX 100
  5.  
  6. int id[MAX];
  7. char fn[MAX][SIZE];
  8. char f[MAX];
  9. char l[MAX];
  10. char ln[MAX][SIZE];
  11. char mi[MAX][SIZE];
  12. char m[MAX];
  13.  
  14. int menu()
  15. {
  16. int i,s=0;
  17.  
  18. while(s<1|| s>4)
  19. {
  20. clrscr();
  21. gotoxy(5,5);
  22. printf("menu");
  23. gotoxy(5,7);
  24. printf("1.insert");
  25. gotoxy(5,9);
  26. printf("2.delete");
  27. gotoxy(5,11);
  28. printf("3.Display all");
  29. gotoxy(5,13);
  30. printf("4.Quit");
  31. gotoxy(5,15);
  32. printf("Select(1-4): ");
  33. scanf("%d",&s);
  34. }
  35. return (s);
  36. }
  37.  
  38. void insert(int idn,int id[MAX],char fn[MAX],char f[MAX],char ln[MAX],char l[MAX],char mi[MAX],char m[MAX])
  39. {
  40. int i,p;
  41. i=p=0;
  42. while(idn>id[i] && id[i]!=-1)
  43. i++;
  44. p=i;
  45. if(id[i]==-1)
  46. {
  47. id[p]=idn;
  48. strcpy(f[i],fn);
  49. strcpy(l[i],ln);
  50. strcpy(m[i],mi);
  51. }
  52.  
  53. else
  54. {
  55. for(i=end(id);i>p;i--)
  56. {
  57. id[i]=id[i-1];
  58. strcpy(f[i],f[i-1]);
  59. strcpy(l[i],l[i-1]);
  60. strcpy(m[i],mi[i-1]);
  61. }
  62.  
  63.  
  64. }
  65. }
  66. void initialize(int id[MAX])
  67. {
  68. int i=0;
  69. for(i=0;i<MAX;i++)
  70. {
  71. id[i]=-1;
  72. f[i]=-1;
  73. l[i]=-1;
  74. m[i]=-1;
  75. }
  76. }
  77.  
  78. int end(int id[MAX])
  79. { int i=0;
  80. while(id[i]!=-1)
  81. i++;
  82. return(i);
  83. }
  84.  
  85. void delete(int idn,int id[MAX])
  86. {
  87. int i,p;
  88. p=locate(idn,id);
  89.  
  90. if(p<0){
  91. printf("record not found");
  92. getch();
  93. exit(0);
  94. }
  95. else
  96. for(i=p;i<end(id);i++)
  97. {
  98. id[i]=id[i+1];
  99. strcpy(fn[i],fn[i+1]);
  100. strcpy(ln[i],ln[i+1]);
  101. strcpy(mi[i],mi[i+1]);
  102. }
  103. }
  104.  
  105. int locate(int idn,int id[MAX])
  106. {int i=0;
  107. while(idn!=id[i] && id[i]!=-1)
  108. i++;
  109.  
  110. if(id[i]==-1)
  111. return(-1);
  112. else
  113. return(i);
  114. }
  115.  
  116. void displayall(int id[MAX],char f[MAX],char l[MAX],char m[MAX])
  117. {
  118. int i;
  119. for(i=0;i<end(id);i++)
  120. {
  121. gotoxy(5,5);
  122. printf(" idnum fname lstnme midntl");
  123. gotoxy(7,9+i);
  124. printf(" %d %d %s %s %s ",i+1,id[i],f[i],l[i],m[i]);
  125. getch();
  126. }
  127. }
  128.  
  129.  
  130. main()
  131. {
  132. int i,idn;
  133. char fn[MAX];
  134. char ln[MAX];
  135. char mi[MAX];
  136. initialize(id);
  137. while(1){
  138. i=menu();
  139. switch(i){
  140. case 1: clrscr();
  141. printf("\nInput number: ");scanf("%d",&idn);
  142. printf("\nInput first name: ");scanf("%s",&fn);
  143. printf("\nInput last name: ");scanf("%s",&ln);
  144. printf("\nInput middle initial: ");scanf("%s",&mi);
  145. insert(idn,id,fn,f,ln,l,mi,m);break;
  146. case 2:
  147. clrscr();
  148. printf("\nInput number: ");scanf("%d",&idn);
  149. delete(idn,id);break;
  150. case 3:
  151. clrscr();displayall(id,f,l,m);break;
  152. case 4:
  153. exit(0);
  154. }
  155. getche();
  156. }
  157. }

  1. #include<stdio.h>
  2. #include<string.h>
  3. #define SIZE 5
  4. #define MAX 100
  5.  
  6. int id[MAX];
  7. char fn[MAX][SIZE];
  8. char f[MAX];
  9. char l[MAX];
  10. char ln[MAX][SIZE];
  11. char mi[MAX][SIZE];
  12. char m[MAX];
  13.  
  14. int menu()
  15. {
  16. int i,s=0;
  17.  
  18. while(s<1|| s>4)
  19. {
  20. clrscr();
  21. gotoxy(5,5);
  22. printf("menu");
  23. gotoxy(5,7);
  24. printf("1.insert");
  25. gotoxy(5,9);
  26. printf("2.delete");
  27. gotoxy(5,11);
  28. printf("3.Display all");
  29. gotoxy(5,13);
  30. printf("4.Quit");
  31. gotoxy(5,15);
  32. printf("Select(1-4): ");
  33. scanf("%d",&s);
  34. }
  35. return (s);
  36. }
  37.  
  38. void insert(int idn,int id[MAX],char fn[MAX],char f[MAX],char ln[MAX],char l[MAX],char mi[MAX],char m[MAX])
  39. {
  40. int i,p;
  41. i=p=0;
  42. while(idn>id[i] && id[i]!=-1)
  43. i++;
  44. p=i;
  45. if(id[i]==-1)
  46. {
  47. id[p]=idn;
  48. strcpy(f[i],fn);
  49. strcpy(l[i],ln);
  50. strcpy(m[i],mi);
  51. }
  52.  
  53. else
  54. {
  55. for(i=end(id);i>p;i--)
  56. {
  57. id[i]=id[i-1];
  58. strcpy(f[i],f[i-1]);
  59. strcpy(l[i],l[i-1]);
  60. strcpy(m[i],mi[i-1]);
  61. }
  62.  
  63.  
  64. }
  65. }
  66. void initialize(int id[MAX])
  67. {
  68. int i=0;
  69. for(i=0;i<MAX;i++)
  70. {
  71. id[i]=-1;
  72. f[i]=-1;
  73. l[i]=-1;
  74. m[i]=-1;
  75. }
  76. }
  77.  
  78. int end(int id[MAX])
  79. { int i=0;
  80. while(id[i]!=-1)
  81. i++;
  82. return(i);
  83. }
  84.  
  85. void delete(int idn,int id[MAX])
  86. {
  87. int i,p;
  88. p=locate(idn,id);
  89.  
  90. if(p<0){
  91. printf("record not found");
  92. getch();
  93. exit(0);
  94. }
  95. else
  96. for(i=p;i<end(id);i++)
  97. {
  98. id[i]=id[i+1];
  99. strcpy(fn[i],fn[i+1]);
  100. strcpy(ln[i],ln[i+1]);
  101. strcpy(mi[i],mi[i+1]);
  102. }
  103. }
  104.  
  105. int locate(int idn,int id[MAX])
  106. {int i=0;
  107. while(idn!=id[i] && id[i]!=-1)
  108. i++;
  109.  
  110. if(id[i]==-1)
  111. return(-1);
  112. else
  113. return(i);
  114. }
  115.  
  116. void displayall(int id[MAX],char f[MAX],char l[MAX],char m[MAX])
  117. {
  118. int i;
  119. for(i=0;i<end(id);i++)
  120. {
  121. gotoxy(5,5);
  122. printf(" idnum fname lstnme midntl");
  123. gotoxy(7,9+i);
  124. printf(" %d %d %s %s %s ",i+1,id[i],f[i],l[i],m[i]);
  125. getch();
  126. }
  127. }
  128.  
  129.  
  130. main()
  131. {
  132. int i,idn;
  133. char fn[MAX];
  134. char ln[MAX];
  135. char mi[MAX];
  136. initialize(id);
  137. while(1)
  138. {
  139. i=menu();
  140. switch(i)
  141. {
  142.  
  143. case 1: clrscr();
  144. printf("\nInput number: ");scanf("%d",&idn);
  145. printf("\nInput first name: ");scanf("%s",&fn);
  146. printf("\nInput last name: ");scanf("%s",&ln);
  147. printf("\nInput middle initial: ");scanf("%s",&mi);
  148. insert(idn,id,fn,f,ln,l,mi,m);break;
  149.  
  150. case 2:
  151. clrscr();
  152. printf("\nInput number: ");scanf("%d",&idn);
  153. delete(idn,id);break;
  154.  
  155. case 3:
  156. clrscr();displayall(id,f,l,m);break;
  157.  
  158. case 4:
  159. exit(0);
  160. }
  161.  
  162. getche();
  163. }
  164. }

i have somewhat found a solution in my program. But there are still some problem in my displayall function. coz when i'm running my program the firstname,lastname and middle initial outputs are all the same. even though i assign it differently. like when i assigned firstname as 'Dave', lastname 'Smith' and mid initial as 'B' it will just give an output of D in all the 3.

what can i do to get 3 different outputs?
pls someone help me
Last edited by Dave Sinkula; Jul 14th, 2006 at 1:41 pm. Reason: Consecutive posts.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,782
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 308
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help!! about ADT list please

 
0
  #6
Jul 14th, 2006
Threads merged. Some duplication removed. Code tags added -- learn to use them.
“The essential notion of a socialist society is force.”
— Milton Friedman
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,898
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 302
Lerner Lerner is offline Offline
Posting Virtuoso

Re: help!! about ADT list please

 
0
  #7
Jul 14th, 2006
id, f, l, and m are all arrays. id is an int array which may contain up to MAX = 100 ints. The first int in id is id[0], the second is id[1], the third is id[2], etc. f, l, and m are char arrays. If the char array is null terminated then f, l, and m are Cstyle strings. The first char in f is f[0], the second char in f is f[1], etc, very similar to each int in id. However, if you want to display a string then you don't display a single char, unless the string is just one char long. Therefore, this:

printf(" %d %d %s %s %s ",i+1,id[i],f[i],l[i],m[i]);

should probably be more like this:

printf(" %d %d %s %s %s ",i+1,id[i],f,l,m);

Now if what's in f, l, m are the same the output should be the same, and if they aren't the same, then the output shouldn't be the same. If they are the same string and you don't want them to be, then the protocol used to assign data to them is in error.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,771
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 493
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: help!! about ADT list please

 
0
  #8
Jul 14th, 2006
Buddy you have got too many errors hanging out there in your code and even your logic is a bit wrong there.

>>>
  1. strcpy(f[i],f[i-1]);
strcpy is used to copy contents from one character array to another. IF you just want to change the char value y not use the assignment stmt. Or do you reallly wnt to copy the character array contents? We have no way of knowing it.

>>>
  1. void delete(int idn,int id[MAX])

delete is a reserved keyword used to free the memory block pointed by a pointer. This is a violation.

Basically i think you are confusing yourself between character and character arrays called as strings. Read some good articles so that your basics are a bit clear.

Hope it helped. Bye.
Last edited by ~s.o.s~; Jul 14th, 2006 at 3:42 pm.
I don't accept change; I don't deserve to live.

Sacrifice is a painful, pure and beautiful thing.

Dammit, Jones, What the Hell Are Knoll Pointers?!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 38
Reputation: comp_sci11 is an unknown quantity at this point 
Solved Threads: 0
comp_sci11's Avatar
comp_sci11 comp_sci11 is offline Offline
Light Poster

Re: help!! about ADT list please

 
0
  #9
Jul 15th, 2006
thanks 4 those who replied! I'm somehow debug my program a lil'bit but there are still some problems. here is my new code wherein I added some more...(like q1,q2,q3 etc....)

#include<stdio.h>
#include<string.h>
#define SIZE 5
#define MAX 10

int id[MAX];
char fn[MAX][SIZE];
char f[MAX];
char l[MAX];
char ln[MAX][SIZE];
char mi[MAX][SIZE];
char m[MAX];
int q1[MAX];
int q4[MAX];
int q2[MAX];
int q5[MAX];
int q3[MAX];
int q6[MAX];

int menu()
{
int i,s=0;

while(s<1|| s>4)
{
clrscr();
gotoxy(5,5);
printf("menu");
gotoxy(5,7);
printf("1.insert");
gotoxy(5,9);
printf("2.delete");
gotoxy(5,11);
printf("3.Display all");
gotoxy(5,13);
printf("4.Quit");
gotoxy(5,15);
printf("Select(1-4): ");
scanf("%d",&s);
}
return (s);
}

void insert(int idn,int id[MAX],char fn[MAX],char f[MAX],char ln[MAX],char l[MAX],char mi[MAX],char m[MAX],int q1[MAX],int q4[MAX],int q2[MAX],int q5[MAX],int q3[MAX],int q6[MAX])
{
int i,p;
i=p=0;
while(idn>id[i] && id[i]!=-1)
i++;
p=i;
if(id[i]==-1)
{
id[p]=idn;
strcpy(f[i],fn);
strcpy(l[i],ln);
strcpy(m[i],mi);
q4[i]=q1;
q5[i]=q2;
q6[i]=q3;
}

else
{
for(i=end(id);i>p;i--)
{
id[i]=id[i-1];
strcpy(f[i],f[i-1]);
strcpy(l[i],l[i-1]);
strcpy(m[i],m[i-1]);
q4[i]=q4[i-1];
q5[i]=q5[i-1];
q6[i]=q6[i-1];
}


}
}
void initialize(int id[MAX])
{
int i=0;
for(i=0;i<MAX;i++)
{
id[i]=-1;
f[i]=-1;
l[i]=-1;
m[i]=-1;
q4[i]=-1;
q5[i]=-1;
q6[i]=-1;
}
}

int end(int id[MAX])
{ int i=0;
while(id[i]!=-1)
i++;
return(i);
}

void delete(int idn,int id[MAX])
{
int i,p;
p=locate(idn,id);

if(p<0){
printf("record not found");
getch();
exit(0);
}
else
for(i=p;i<end(id);i++)
{
id[i]=id[i+1];
strcpy(f[i],f[i+1]);
strcpy(l[i],l[i+1]);
strcpy(m[i],m[i+1]);
q4[i]=q4[i+1];
q5[i]=q5[i+1];
q6[i]=q6[i+1];
}
}

int locate(int idn,int id[MAX])
{int i=0;
while(idn!=id[i] && id[i]!=-1)
i++;

if(id[i]==-1)
return(-1);
else
return(i);
}

void displayall(int id[MAX],int idn[MAX],char f[MAX],char fn[MAX],char l[MAX],char ln[MAX],char m[MAX],char mi[MAX],int q1[MAX],int q4[MAX],int q2[MAX],int q5[MAX],int q3[MAX],int q6[MAX])
{
int i;
for(i=0;i<end(id);i++)
{
gotoxy(5,5);
printf(" idnum fname lstnme midntl q1 q2 q3");
gotoxy(7,9+i);
printf(" %d %d %s %s %s %d %d %d",i+1, id[i], fn, ln, mi,q1[i],q2[i],q3[i]);
getche();
}
}


main()
{
int i,idn;
char fn[MAX][SIZE];
char ln[MAX][SIZE];
char mi[MAX][2];
int q1[MAX];
int q4[MAX];
int q2[MAX];
int q5[MAX];
int q3[MAX];
int q6[MAX];
initialize(id);
while(1){
i=menu();
switch(i){
case 1: clrscr();
printf("\nInput number: ");scanf("%d",&idn);
printf("\nInput first name: ");scanf("%s",&fn);
printf("\nInput last name: ");scanf("%s",&ln);
printf("\nInput middle initial: ");scanf("%s",&mi);
printf("\nInput quiz 1: ");scanf("%d",&q1);
printf("\nInput quiz 2:");scanf("%d",&q2);
printf("\nInput quiz 3:");scanf("%d",&q3);
insert(idn,id,fn,f,ln,l,mi,m,q1,q4,q2,q5,q3,q6);break;
case 2:
clrscr();
printf("\nInput number: ");scanf("%d",&idn);
delete(idn,id);break;
case 3:
clrscr();displayall(id,idn,f,fn,l,ln,m,mi,q1,q4,q2,q5,q3,q6);break;
case 4:
exit(0);
}
getche();
}
}


in this code i've created i've somehow solved my previous problem wherein I've already got a different output(in the 3 array of strings) unlike before.
BUT now my problem is, when i try to add another inputs using the insert function. It just display the second output.
Last edited by comp_sci11; Jul 15th, 2006 at 5:04 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 38
Reputation: comp_sci11 is an unknown quantity at this point 
Solved Threads: 0
comp_sci11's Avatar
comp_sci11 comp_sci11 is offline Offline
Light Poster

Re: help!! about ADT list please

 
0
  #10
Jul 15th, 2006
here is an example of what i'm talking about:

my first inputs are:
idnum: 2
firstname: dave
lastname: smith
middle initial: s
quiz 1: 1
quiz 2: 2
quiz 3: 3

my second inputs are:
idnum: 2
firstname: daniel
lastname: howard
middle initial: q
quiz 1: 2
quiz 2: 5
quiz 3: 6



but it will give an output like this:




idnum fname lstnme midntl q1 q2 q3
1 1 daniel howard q 2 5 6
2 2 daniel howard q 0 0 0






instead of:


idnum fname lstnme midntl q1 q2 q3
1 1 dave smith s 1 2 3
2 2 daniel howard q 2 5 6




how can I solve this problem??
Last edited by comp_sci11; Jul 15th, 2006 at 5:14 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 1356 | Replies: 9
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC