Monday, July 27, 2009

How would I get out of this loop in C? (programming question)?

I want to get out of this loop if the user presses the enter key (with no information inputed) for the 'class name'. Here is the code:





do


{


system("cls");





printf("Student: %s\n\n", studentName);


printf("Course %d:\n", *count);


fflush(stdin);





printf("\n\tCourse Name: ");


gets(courseName[arrayCount]);


fflush(stdin);





printf("\n\tDepartment: ");


gets(courseDepartment[arrayCount]);


fflush(stdin);





printf("\n\tCourse #: ");


scanf("%d", %26amp;courseNumber[arrayCount]);


fflush(stdin);





printf("\n\tSection: ");


gets(sectionCode[arrayCount]);


fflush(stdin);





printf("\n\tCredits: ");


scanf("%f", %26amp;creditAmount[arrayCount]);


fflush(stdin);





printf("\n\tLab Class(y or n): ");


scanf("%c", %26amp;labStatus[arrayCount]);


fflush(stdin);





*count += 1;


arrayCount += 1;


} while (*count %26lt; 4);

How would I get out of this loop in C? (programming question)?
I am a little rusty on C.





Could you use a simple "if... then"? I would place it immediately after the user enters for courseName





if (!courseName[arrayCount]) then {


break;


}
Reply:use kbhit -


http://www.cprogramming.com/fod/kbhit.ht...


No comments:

Post a Comment