Как хранить и обновлять строку массива на языке Си ?
Я хотел сохранить адрес в разделе switch case 7: в программе. когда я нажимаю 7, должен отображаться адрес, который будет ранее сохранен, а также должна быть возможность обновления нового адреса. Но когда я нажимаю 7, ничего не происходит.
Что я уже пробовал:
//Program to display student information #include<stdio.h> #include<stdlib.h> int choice, enrol, batch; char a[30]={"Any address"}; int i=0; void main() { do { printf("\n---------------------Student Information Section--------------------------"); printf("\n\n1. Student Information\n"); printf("2. Course Material Despatch Status\n"); printf("3. Fee Status\n"); printf("4. Time Table For Theory Counselling\n"); printf("5. Time Table For Practical Counselling\n"); printf("6. Assignment Submission Schedule\n"); printf("7. Change Of The Correspondence Address\n"); printf("8. General Queries\n"); printf("9. Quit"); printf("-------------------------------------\n\n"); printf("\nEnter your choice: "); scanf("%d", &choice); switch (choice) { case 1: while(enrol!=1234) { printf("\nEnter Your Enrolment Number: "); scanf("%d", &enrol); if (enrol != 1234) printf("\nPlease Enter a valid Enrolment No.\n"); } printf("\n\n********BCA PROGRAMME********"); printf("\nCourse duration Minimum 3 years Maximum 6 Years"); printf("\nYear of Study 2017"); printf("\nRegistered Semester II"); printf("\nStudy Center Guwahati"); printf("\nRegional Center Guwahati"); printf("\nFees paid For Per Semester 6000/-"); printf("\nBatch No: 5"); printf("\nClass duration will be one and half an hour"); break; case 2: printf("\nStudy material is despatched."); break; case 3: printf("\nFees is Paid For Semester II: 6000/-"); break; case 4: while(batch!=5) { printf("\nEnter Your Batch Number: "); scanf("%d", &batch); printf("\nTheory counselling will start from 9 AM\nPlease visit study centre for complete details.\n"); if (batch != 5) printf("\nPlease Enter a valid Batch No.\n"); } break; case 5: while(batch!=5) { printf("\nEnter Your Batch Number: "); scanf("%d", &batch); printf("\nPractical counselling will start from 9 AM\nPlease visit study centre for complete details.\n"); if (batch != 5) printf("\nPlease Enter a valid Batch No.\n"); } break; case 6: printf("Last date of submission of assignment"); printf("\nFor July-December Session is 15th october 2017"); printf("\nFor January-June Session is 15th April 2018"); break; case 7: while( (a[i++]=getchar()) != '\n' && i < 30) /* take input from user until it's a newline or equal to 30 */ ; a[i] = '\0'; /* null-terminate the string */ i = 0; while(a[i] != '\0') /* print until we've hit \0 */ printf("%c",a[i++]); break; case 8: printf("\n---------Frequently Asked Questions-----------"); printf("\n\n\nQ)What is Academic Schedule?"); printf("\nAdmission to various programmes of the \nUniversity are open as per the Academic Calendar."); printf("\n\nQ)What is the fee Amount & Mode of the Payment?"); printf("\nYou can pay using online portal or by bank draft."); printf("\n\nQ)When will I be notified of my acceptance?"); printf("\nYou will be notified of your acceptance usually\nwithin two months after the receipt of your application."); printf("\n\nQ)What is an auto generated Control Number?"); printf("\nAn auto generated Control Number is allotted\nprovisionally after submission of online application form."); printf("\n\nQ)What if I forget to take printout of Online Application Form after submission?"); printf("You can download it again from the print application section.\n\n\n"); break; case 9: exit(0); default:printf("wrong choice\n"); } } while(choice>'1' || choice<'9'); }
jeron1
Первое, что вы делаете в случае 7: это ждете ввода пользователя, а не выводите предыдущий ввод.
munsine
Не могли бы вы объяснить, пожалуйста ? или добавить решение