Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
Most of my experience is limited to SQL scripting for DBA functions. I am a security specialist and provide help to others on those topics, but I am learning C to aid in those other endeavors. I've been reading books, writing small programs, and expanding the difficulty level as I go. This is the first time I've had to reach out for help. I apologize if this has been asked, but I did search first and didn't find anything.
So far, my programs have always returned only the valid data from partially filled arrays. This particular one is not behaving the same even though I'm using the same for statement I have previously used with success. At this point I must have tunnel vision because I cannot seem to see where this is failing.
If there are fewer than 20 inputs, the printf output displays the remaining values with garbage. It would be greatly appreciated if someone could provide some guidance on what I'm overlooking. Thank you in advance.
#include #include #include struct grade { int id; int percent; }; #define maxCount 100 int main() { int *grade; struct grade gradeBook[maxCount]; int count = 0; char YN; int i; for(i = 0; i < maxCount; i++) { printf("Enter ID: "); scanf("%d", &gradeBook[i].id); printf("Enter grade from 0-100: "); scanf("%d", &gradeBook[i].percent); count++; // Prompt to continue, break if done printf("Do you want to Continue? (Y/N)"); scanf(" %c", &YN); if(YN == 'n' || YN == 'N') { break; } } void sort(struct grade gradeBook[],int cnt) { int i, j; struct grade temp; for (i = 0; i < (cnt - 1); i++) { for (j = (i + 1); j < cnt; j++) { if(gradeBook[j].id < gradeBook[i].id) { temp = gradeBook[j]; gradeBook[j] = gradeBook[i]; gradeBook[i] = temp; } } } } printf("Grades entered and ordered by ID: \n"); for (i = 0; i < count; i++) { printf("\nID:%d, Grade: %3d\n", REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
If there are fewer than 20 inputs, the printf output displays the remaining values with garbage
What else did you expect?
If you have fewer than 20 inputs, then the remaining inputs have not been given any value. You say "partial array input" but you literally asked the computer to loop over the entire array.
It's really not clear what else you expected to happen here.
Perhaps loop to count the second time instead.
count
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.