file and multidimensional array

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 1
Reputation: kgbalaji1980 is an unknown quantity at this point 
Solved Threads: 0
kgbalaji1980 kgbalaji1980 is offline Offline
Newbie Poster

file and multidimensional array

 
0
  #1
Aug 6th, 2007
Hi,

I need help for this C Program very urgent. please find the attachment below
Attached Files
File Type: doc q2[1].doc (92.5 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: file and multidimensional array

 
0
  #2
Aug 6th, 2007
> I need help for this C Program very urgent
http://www.catb.org/~esr/faqs/smart-...ns.html#urgent
Urgency is your problem, not mine.

> please find the attachment below
http://www.catb.org/~esr/faqs/smart-...s.html#formats
I'm not interested in even risking downloading a non-portable file format which is prone to all sorts of virus infections.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,445
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: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: file and multidimensional array

 
0
  #3
Aug 6th, 2007
>>I'm not interested in even risking downloading a non-portable file format which is prone to all sorts of virus infections

Absolutely agree with that -- *.doc files have been known to contains viruses, worms and other kinds of animals. Kg: save your program as *.c and either post it or attach it if its too big to post.
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: file and multidimensional array

 
0
  #4
Aug 6th, 2007
Originally Posted by kgbalaji1980 View Post
Hi,

I need help for this C Program very urgent. please find the attachment below
Post what the program is suppose to do, and what is not doing correctly. Post any error messages you are getting at compile time, in essence tell us what's the problem that you are having with it.

And then, maybe we could help.
Last edited by Aia; Aug 6th, 2007 at 6:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 12
Reputation: ashishtrivedi is an unknown quantity at this point 
Solved Threads: 2
ashishtrivedi ashishtrivedi is offline Offline
Newbie Poster

Re: file and multidimensional array

 
0
  #5
Aug 8th, 2007
Hi There,
Here you go. Please find your requsted program below.
  1. /******************************************************************************\
  2.  * QUESTION #2 *
  3.  * Create a program that will keep track of 5 students and their grades. *
  4.  * The grades will be kept in an array of up to 10 grades. *
  5.  * To do this, you will need to create a multi-dimensional array of grades *
  6.  * where each column (or row) is assigned to each student. *
  7. \******************************************************************************/
  8.  
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. float grade[5][10];
  17. char *StudentNames[5]= {0};
  18. int totalStudent=0;
  19.  
  20. int AddStudentName(void);
  21. int EnterGrades(void);
  22. int DisplayData(void);
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26. int i=0,j=0;
  27. for(i=0;i<5;i++)
  28. for(j=0;j<10;j++)
  29. grade[i][j] = -1;
  30.  
  31.  
  32. while(1)
  33. {
  34. char choice;
  35. printf("\n\n\n\n");
  36. printf("\n/**********************************************************\\");
  37. printf("\n * Chioce Function *");
  38. printf("\n ********************************************************* ");
  39. printf("\n * 1 Add student name. *");
  40. printf("\n * 2 Enter Grades. *");
  41. printf("\n * 3 Display student-grade data. *");
  42. printf("\n * Any othey key Exit program. *");
  43. printf("\n\\**********************************************************/");
  44. printf("\nEnter Chioce:..");
  45. choice=getche();
  46. switch(choice)
  47. {
  48. case '1':
  49. AddStudentName();
  50. break;
  51. case '2':
  52. EnterGrades();
  53. break;
  54. case '3':
  55. DisplayData();
  56. break;
  57. default:
  58. return 0;
  59. }
  60.  
  61. }
  62.  
  63.  
  64. return 0;
  65. } //end main
  66.  
  67. int AddStudentName(void)
  68. {
  69. if(totalStudent < 5)
  70. {
  71. char sName[50]={0};
  72. totalStudent++;
  73. printf("\nEnter Student %d name(default-Student%d) : ",totalStudent,totalStudent);
  74. flushall();
  75. gets(sName);
  76. if(strlen(sName)==0)
  77. sprintf(sName,"Student%d",totalStudent);
  78.  
  79. StudentNames[totalStudent-1] = (char *)calloc(strlen(sName)+1,sizeof(char));
  80. strncpy(StudentNames[totalStudent-1],sName,strlen(sName));
  81.  
  82. }
  83. else
  84. {
  85. printf("\n **** Maximum 5 student can be entered. Press any key to continue.");
  86. getch();
  87. }
  88. return 0;
  89. }
  90. int EnterGrades(void)
  91. {
  92. if(totalStudent != 0)
  93. {
  94. int studentNo=0, j=0;
  95. int choice;
  96. printf("\nChoice - Student Name");
  97. for(;studentNo<totalStudent;studentNo++)
  98. printf("\n%4d - %s",studentNo+1,StudentNames[studentNo]);
  99.  
  100. printf("\n\nSelect student for whom you want to enter grade. Enter chioce...");
  101. choice = getche();
  102. studentNo = choice-1-'0';
  103.  
  104. while(j<10 && grade[studentNo][j]!=-1) j++;
  105.  
  106. if(j==10)
  107. printf("\n10 grades already entered for the selected student. No more grade can be entered.");
  108. else
  109. {
  110. printf("\n Enter Grade : ");
  111. scanf("%f",&grade[studentNo][j]);
  112. }
  113. }
  114. else
  115. {
  116. printf("\nPlease Enter student Names first. Press any key to continue.");
  117. getch();
  118. }
  119.  
  120. return 0;
  121. }
  122. int DisplayData(void)
  123. {
  124. if(totalStudent != 0)
  125. {
  126. int i=0,j=0;
  127. for(i=0;i<totalStudent;i++)
  128. {
  129. if(StudentNames[i]!=0)
  130. printf("\n Student Name : %s",StudentNames[i]);
  131.  
  132. for(j=0;j<10;j++)
  133. {
  134. if(grade[i][j]!=-1)
  135. printf("\n\t\t - Grade %d = %d", j+1, grade[i][j]);
  136. else if(j==0)
  137. {
  138. printf("\n\t** No Grade entered for the student..\n");
  139. break;
  140. }
  141. else
  142. {
  143. printf("\n");
  144. break;
  145. }
  146.  
  147. }
  148. }
  149. printf("\n == End of data.. == \n");
  150. }
  151. else
  152. {
  153. printf("\n======== No data to Display. ========= Press any key to continue.");
  154. getch();
  155. }
  156. getch();
  157. return 0;
  158. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: file and multidimensional array

 
0
  #6
Aug 9th, 2007
  1. gets(sName);

Definitely a show stopper. Do yourself a favor and don't
use gets() anymore. Forget that it exists. Here's why.

  1. #include <conio.h>
  2.  
  3. flushall();
  4. getch();

These are not C standards. Best to not use them, specially
to help other people.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,445
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: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: file and multidimensional array

 
0
  #7
Aug 9th, 2007
>>These are not C standards
you are right -- getch() is non-standard, but flushall() is. Its declared in stdio.h.
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.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC