![]() |
|
#1
|
|||
|
|||
C Code i need help for printingCPP / C++ / C Code:
![]() |
|||
|
#2
|
||||
|
||||
Re: C Code i need help for printingWhoa hoss... that's a buch of code with nothing telling us what you are wanting help with besides... "printing". We need more information on the specific problem that you are having... where you think this might be happeneing... and PLEASE put the following tags around your code next time [/c] after the block of code... and [c] before the block of code.
Thanks. __________________
If practice makes perfect and nobody's perfect... why practice? Homepage: http://www.treywhite.com Blog: http://www.treywhite.com/blog.php Web Design Company: http://www.ewebproductions.com |
|
#3
|
|||
|
|||
Re: C Code i need help for printinghello
this code suppose to have to construct one is holding student info such as grade ,student name,and pointers .next;for the department struct it hold the department name,code ,and refrence to student struct this code suppose to read the student info and deparment info and display the information from the depart that a student is in it is like that deN studentInfo studentName GPA Eng Ghon 2 CS Alex 3 Please i need help it looks like 2D array my problem is to print the student info according to the department he is like dept[1].shead should display Eng Ghon 2 another question what do you mean by using tag and how to use it |
|
#4
|
||||
|
||||
Re: C Code i need help for printingFirst of all... there were several errors when I tried to compile the code:
#1) addStudent prototype * no identifier for the Department pointer * no identifier for the int parameter * no structure named for the student structure pointer #2) need to add the keyword struct in front of your structure name in the function prototype #3) Need to add the keyword struct in front of your structure initialization of Student st1 #4) Need to add the keyword struct in front of your structure initialization of Department Dept #5) You always want main to have a return type of int in C... so that needs to be changed #6) Unlike Java and C++ you can't initialize a variable in a function in a for loop for instance. Initialize that int i (the counter in the for loop) at the start of the main function. #7 and #8 ) Add the keyword struct in the 2 malloc() calls in the getDeptInfo() function when trying to allocate the memory. #9) Add the keyword struct in for the print function parameter Department *head. #10) Add the keyword struct for the student s initialization in the print() function. #11) Add the keyword struct for the return type of the readStu() function. #12) Add the keyword struct in front of student in the malloc() call in the readStu() function. Here is the code after those are corrected and white space was taken out: CPP / C++ / C Code:
After running the program... here is the output. Tell me what should be happening: Please enter the number of DEPARTMENT: 1 Please enter Department name : Finance Please enter Department Cpde : 999 Please enter Department Number : 123999 Please enter student name : Trey Please enter student GPA : 4 Please enter Department name : Accounting Please enter Department Cpde : 998 Please enter Department Number : 123998 Please enter student name : Joe Please enter student GPA : 3 The DEPARTMENT Name Is Accounting The DEPARTMENT Code Is 998 The DEPARTMENT Number Is 123998 __________________
If practice makes perfect and nobody's perfect... why practice? Homepage: http://www.treywhite.com Blog: http://www.treywhite.com/blog.php Web Design Company: http://www.ewebproductions.com |
|
#5
|
|||
|
|||
Re: C Code i need help for printinghello:
this code suppose to read student information and store it in linked list then according to the department student information should be displayed the reading from the user input and display the student information according to the department they are located in |
|
#6
|
|||
|
|||
Re: C Code i need help for printingDear this code suppose to display the students name and GPA according to the department they are in
if the department name is Enginnering we enter student name and GPA suppose we enter 15 student in Engineering and 20 student in Computer we need to display Deparment No with department code,department name,and student name,GPA CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: C Code i need help for printingQuote:
Count how many mallocs you have and then count how many frees you have. Didn't I already discuss with you the need for a corresponding free for every malloc? What you need to do is to rewrite your code so that you have a properly implemented Linked List with a "Node" for every element in the list. Then implement your student structure so that you can add it as a node data member so that you separate the linked list functionality from the actual data related to students and departments. Once you have a generic linked list implemented, then you can easily: CPP / C++ / C Code:
It seems that you want a "Departments" linked list to own some number of students and inside of that structure that you've declared is a pointer to a student "head" node (aka element). You should probably declare your Department structure such that it contains a linked list of Students, not a "Shead" member that is really a pointer to student structure: CPP / C++ / C Code:
If you have a "Department" structure, its members do not really need to have "dept" in them. For example: CPP / C++ / C Code:
Do you see how redundant it is to have the "dept" prefacing every member variable of Department? If we are already using/accessing a Department structure, then its members should related somehow to department. CPP / C++ / C Code:
...is a better choice because of: CPP / C++ / C Code:
Easy, huh? I don't see how an integer GPA member of student is going to actually work, unless you're using 1000ths or something as the base such that 3500 = 3.50. I recommended using float, but I guess that didn't work for your needs? What you're trying to do is make a bad design work...and, until you fix your code so that you free your allocated memory regions, there isn't much more that I can do to help you. Why are you writing this code? Is it for a programming class or because you're trying to implement some functionality for a school? :davis: |
|
#8
|
|||
|
|||
Re: C Code i need help for printingDear this code suppose to display the students name and GPA according to the department they are in
if the department name is Enginnering we enter student name and GPA suppose we enter 15 student in Engineering and 20 student in Computer we need to display Deparment No with department code,department name,and student name,GPA CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
Re: C Code i need help for printingUmmm, Batman...I think that the Riddler has been up to his old tricks again, since www.gidforums.com is identical to www.gidforums.com maybe you could modify your code so that it frees the memory you allocate before posting it again?
:davis: |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Formatting C / C++ code | WaltP | C Programming Language | 1 | 07-Jan-2008 00:59 |
| Image processing:Stentiford and Holt Thinning Source code in C or C++ | ladyscarlet99 | C++ Forum | 1 | 09-Sep-2005 04:29 |
| Guidelines for posting requests for help - UPDATED! | WaltP | C++ Forum | 0 | 21-Apr-2005 03:44 |
| Problem with int mixed with char,... | leitz | C++ Forum | 17 | 07-Dec-2004 21:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The