arlir 0 Newbie Poster

Hi there every body, i am trying to build this contact list to hold records for a purpoted library but i got a little stuck with a few issues that i would like you guys to look at. The fifth switch(delete) statement does behave strangely i should say. When I start the program and delete a record, it shows the record is deleted when you check via the view item on the menu. But should I restart the program, the record deleted resurfaces among other records(it is more of deleting a record temporarily in my view which is not what intend of course). I am not sure if it is because of the model i have used to construct the code or otherwise but i wanted to try using something other than using functions for the main items as used in the switch statement. if someone has experienced the same scenrio, i would like to know how i can fix this with their help

I was trying to do some real validation but hit the wall in some areas. On lines 42 and 43, i declared two variables of type char and initialised them as you can see. My intention was to try to validate an email entered by the user as you can see but i realise the thing isn't working as I expected.
Look at lines 132-140, i was trying to find characters other than alphabets but it couldnn't work out too.Someone more comfortable with this can give a hand.

The other thing perhaps i need help with is how I can make every id number unique so i can use this to query the database for a particular record. I did try to start up something from line 435-447 but soon ran out of ideas.

The last issue is with the entire program itself in the way it responds. When I select an item, say view records, it does so well. But should I return to the menu from there and select another operation like modify or delete record, it starts behaving strangely like it will skip everything and display the last message like "Do you want to modify another record" or "Do you want to delete another record". I am not sure really why this is happening. You guys out there do advise me and comment on the general program, design, logic and any other thing you feel needs to be altered.
Many thanks in advance and am looking forward to your responses

`Inline C

  1. #include<conio.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #include<ctype.h>
  6. /* prototypes of functions used in the program*/
  7. void menu(void);
  8. void fname(void);
  9. void lname(void);
  10. void id(void);
  11. void age(void);
  12. void gender(void);
  13. void email(void);
  14. void tel_no(void);
  15. void address(void);
  16. void doj(void);
  17. /declaration of global variables/
  18. int chk,f,t,x,d,m,y,ID,choice;
  19. /structure to hold member details/
  20. struct customer
  21. {
  22. char id[4][4];
  23. char dd[2][3],mth[2][3],yr[4][5];
  24. char l_name[9][9];
  25. char f_name[9][9];
  26. char gender[2][3];
  27. char age[2][2];
  28. char doj[10][10];
  29. char address[25][25];
  30. char tel_num[12][12];
  31. char email[15][15];
  32. }customer_rec;
  33. char ser1,ser2;
  34. char ser='@';
  35. char ser0='.';
  36. void main(void)
  37. {
  38. FILEltlsys,tempdb; /names of files that shall be used in the program/
  39. char again1;
  40. char save_rec;
  41. char access1[6]="lu23ad"; /password for entering the program/
  42. int choice2,chc=0,trk=0;
  43. long int datsize; /* size of the entire file(ltlsys)*/
  44. char fname2[9]; /shall be used to query the database/
  45. /* loop to test password to access the rest of the program*/
  46. while(chc<3)
  47. {
  48. clrscr();
  49. gotoxy(22,7);
  50. printf("WELCOME TO LENNYSVILLE LIBRARY DATABASE");
  51. gotoxy(28,11);
  52. printf("Please,enter your password: ");
  53. gets(access1);
  54. if(strcmp(access1,"lu23ad")!=0)
  55. {
  56. gotoxy(22,21);
  57. printf("You entered an invalid password!");
  58. gotoxy(22,23);
  59. printf(" Please try again");
  60. getch();
  61. clreol();
  62. chc++;
  63. }
  64. else
  65. { /open file for read/write operations/
  66. ltlsys = fopen ( "\LIBUSER.DAT", "rb+" );
  67. if ( ltlsys == NULL )
  68. {
  69. ltlsys = fopen ( "\LIBUSER.DAT","wb+" );
  70. if ( ltlsys == NULL )
  71. {
  72. puts ("Cannot open file!");
  73. exit(1);
  74. }
  75. }
  76. datsize = sizeof(customer_rec); /*assigning the size of the entire file
  77. that holds customer_rec to datsize*/
  78. while(1) /*infinite loop */
  79. {
  80. clrscr();
  81. menu();
  82. switch(choice)
  83. {
  84. case 1:
  85. fseek(ltlsys,0,SEEK_END); /causes the pointer to be set in the disk file to the end to write a new record/
  86. again1='Y';
  87. while(again1=='Y'||again1=='y')
  88. {
  89. gotoxy(5,2);
  90. printf("^^^^^ADD NEW LIBRARY USER^^^^^\n");
  91. printf("\n");
  92. clreol();
  93. do /x,t,f are used as array indexes in the program/
  94. { /they will be used to access different array members/
  95. chk=1;
  96. gotoxy(5,6);
  97. clreol();
  98. printf("Please, enter first name:");
  99. gets(customer_rec.f_name[x]);
  100. if(strlen(customer_rec.f_name[x])>9)
  101. {
  102. gotoxy(23,20);
  103. printf("User name must not be greater than 9 characters\n");
  104. chk=0;
  105. getch();
  106. gotoxy(23,20);
  107. clreol();
  108. }
  109. /* else if(!isalpha(strlen(customer_rec.f_name[x])))
  110. {
  111. gotoxy(23,20);
  112. printf("User name can only have letters\n");
  113. chk=0;
  114. getch();
  115. gotoxy(23,20);
  116. clreol();
  117. }*/
  118. else if(strlen(customer_rec.f_name[x]) == 0)
  119. {
  120. gotoxy(23,20);
  121. printf("User name can not be left blank");
  122. chk=0;
  123. getch();
  124. gotoxy(23,20);
  125. clreol();
  126. }
  127. for(f=x;f<x+1;f++) /*The work of the for loop here is to check if
  128. a digit is entered instead of an alphabet*/
  129. {
  130. for(t=0;t<9;t++)
  131. {
  132. if(isdigit(customer_rec.f_name[f][t]))
  133. {
  134. gotoxy(23,20);
  135. printf("Name can only contain alphabets!");
  136. chk=0;
  137. getch();
  138. gotoxy(23,20);
  139. clreol();
  140. }
  141. }
  142. }
  143. }while(chk==0);
  144. do
  145. {
  146. chk=1;
  147. gotoxy(5,8);
  148. clreol();
  149. printf("Enter last name:");
  150. gets(customer_rec.l_name[x]);
  151. if(strlen(customer_rec.l_name[x])>9)
  152. {
  153. gotoxy(23,20);
  154. printf("User name must not be greater than 9 characters\n");
  155. chk=0;
  156. getch();
  157. gotoxy(23,20);
  158. clreol();
  159. }
  160. else if(strlen(customer_rec.l_name[x]) == 0)
  161. {
  162. gotoxy(23,20);
  163. printf("User name can not be left blank");
  164. chk=0;
  165. getch();
  166. gotoxy(23,20);
  167. clreol();
  168. }
  169. for(f=x;f<x+1;f++)
  170. {
  171. for(t=0;t<9;t++)
  172. {
  173. if(isdigit(customer_rec.l_name[f][t]))
  174. {
  175. gotoxy(23,20);
  176. printf("Name can only contain alphabets!");
  177. chk=0;
  178. getch();
  179. gotoxy(23,20);
  180. clreol();
  181. }
  182. }
  183. }
  184. }while(chk==0);
  185. do
  186. {
  187. chk=1;
  188. gotoxy(5,10);
  189. printf("Enter user's age:");
  190. gets(customer_rec.age[x]);
  191. fflush(stdin);
  192. if (strlen(customer_rec.age[x]) == 0)
  193. {
  194. gotoxy(20,23);
  195. printf("User's age must not be left unfilled");
  196. chk=0;
  197. getch();
  198. gotoxy(20,23);
  199. clreol();
  200. }
  201. else if (strlen(customer_rec.age[x])!=2)
  202. {
  203. gotoxy(20,23);
  204. printf("User's age must be 2 characters long");
  205. chk=0;
  206. getch();
  207. gotoxy(20,23);
  208. clreol();
  209. }
  210. else if(strcmp(customer_rec.age[x],"00")==0)
  211. {
  212. gotoxy(20,23);
  213. printf("User's age cannot be below 1 year");
  214. chk=0;
  215. getch();
  216. gotoxy(20,23);
  217. clreol();
  218. }
  219. for(f=x;f<x+1;f++) /checks to see if somehting other than a digit is entered/
  220. {
  221. for(t=0;t<2;t++)
  222. {
  223. if(!isdigit(customer_rec.age[f][t]))
  224. {
  225. gotoxy(20,23);
  226. printf("Enter a valid age!");
  227. chk=0;
  228. getch();
  229. gotoxy(20,23);
  230. clreol();
  231. }
  232. }
  233. }
  234. }while (chk==0);
  235. do
  236. {
  237. chk=1;
  238. gotoxy(5,12);
  239. clreol();
  240. printf("Enter user's gender[M/F]:");
  241. gets(customer_rec.gender[x]);
  242. if(strlen(customer_rec.gender[x])==0)
  243. {
  244. gotoxy(23,20);
  245. printf("User gender can not be left blank.\n");
  246. chk=0;
  247. getch();
  248. gotoxy(23,20);
  249. clreol();
  250. }
  251. else if(strlen(customer_rec.gender[x])>1)
  252. {
  253. gotoxy(23,20);
  254. printf("Enter M for male or F for female");
  255. chk=0;
  256. getch();
  257. gotoxy(23,20);
  258. clreol();
  259. }
  260. }while(chk==0);
  261. do
  262. {
  263. chk=1;
  264. gotoxy(5,14);
  265. clreol();
  266. printf("Date of joining [dd mm yr]");
  267. printf(" separated by a space: ");
  268. scanf("%s %s %s",customer_rec.dd[x], customer_rec.mth[x], customer_rec.yr[x]);
  269. d = atof(customer_rec.dd[x]); /statement to convert the string in dd to its int eqivalent/
  270. m = atof(customer_rec.mth[x]); /statement to convert the string in mth to its int eqivalent/
  271. y = atof(customer_rec.yr[x]); /*statement to convert the string in yr to its int eqivalent */
  272. if (strlen(customer_rec.dd[x]) == 0)
  273. {
  274. gotoxy(20,23);
  275. printf("Day field must not be left unfilled");
  276. chk=0;
  277. getch();
  278. gotoxy(20,23);
  279. clreol();
  280. }
  281. else if (strlen(customer_rec.dd[x])!=2)
  282. {
  283. gotoxy(20,23);
  284. printf("Day field must be 2 characters long");
  285. chk=0;
  286. getch();
  287. gotoxy(20,23);
  288. clreol();
  289. }
  290. else if(strcmp(customer_rec.dd[x],"00")==0)
  291. {
  292. gotoxy(20,23);
  293. printf("Day cannot be below 1");
  294. chk=0;
  295. getch();
  296. gotoxy(20,23);
  297. clreol();
  298. }
  299. else if(d>31)
  300. {
  301. gotoxy(20,23);
  302. printf("Day value cannot be greater than 31");
  303. chk=0;
  304. getch();
  305. gotoxy(20,23);
  306. clreol();
  307. }
  308. else if (strlen(customer_rec.mth[x]) == 0)
  309. {
  310. gotoxy(20,23);
  311. printf("Month field must not be left unfilled");
  312. chk=0;
  313. getch();
  314. gotoxy(20,23);
  315. clreol();
  316. }
  317. else if (strlen(customer_rec.mth[x])!=2)
  318. {
  319. gotoxy(20,23);
  320. printf("Month field must be 2 characters long");
  321. chk=0;
  322. getch();
  323. gotoxy(20,23);
  324. clreol();
  325. }
  326. else if(strcmp(customer_rec.mth[x],"00")==0)
  327. {
  328. gotoxy(20,23);
  329. printf("Month field cannot be below 1");
  330. chk=0;
  331. getch();
  332. gotoxy(20,23);
  333. clreol();
  334. }
  335. else if(m>12)
  336. {
  337. gotoxy(20,23);
  338. printf("Month value cannot greater than 12");
  339. chk=0;
  340. getch();
  341. gotoxy(20,23);
  342. clreol();
  343. }
  344. else if (strlen(customer_rec.yr[x]) == 0)
  345. {
  346. gotoxy(20,23);
  347. printf("Year field must not be left unfilled");
  348. chk=0;
  349. getch();
  350. gotoxy(20,23);
  351. clreol();
  352. }
  353. else if (strlen(customer_rec.yr[x])!=4)
  354. {
  355. gotoxy(20,23);
  356. printf("Year field must be 4 characters long");
  357. chk=0;
  358. getch();
  359. gotoxy(20,23);
  360. clreol();
  361. }
  362. else if(y<1900)
  363. {
  364. gotoxy(20,23);
  365. printf("Year cannot be below 1900 ");
  366. chk=0;
  367. getch();
  368. gotoxy(20,23);
  369. clreol();
  370. }
  371. }while(chk==0);
  372. do
  373. {
  374. chk=1;
  375. fflush(stdin);
  376. gotoxy(5,16);
  377. clreol();
  378. printf("Enter ID No:");
  379. gets(customer_rec.id[x]);
  380. /*rewind(ltlsys);
  381. fread(&customer_rec,datsize,1,ltlsys);
  382. {
  383. if(strcmp(customer_rec.id[x],ID)==0)
  384. {
  385. gotoxy(23,20);
  386. printf("User id already assigned!\n");
  387. chk=0;
  388. getch();
  389. gotoxy(23,20);
  390. clreol();
  391. }
  392. }*/
  393. if(strlen(customer_rec.id[x])== 0)
  394. {
  395. gotoxy(23,20);
  396. printf("User must be assigned a valid ID!\n");
  397. chk=0;
  398. getch();
  399. gotoxy(23,20);
  400. clreol();
  401. }
  402. else if(strcmp(customer_rec.id[x] ,"0000") == 0)
  403. {
  404. gotoxy(23,20);
  405. printf("User ID is invalid!");
  406. chk=0;
  407. getch();
  408. gotoxy(23,20);
  409. clreol();
  410. }
  411. for(f=x;f<x+1;f++)
  412. {
  413. for(t=0;t<4;t++)
  414. {
  415. if(!isdigit(customer_rec.id[f][t]))
  416. {
  417. gotoxy(23,20);
  418. printf("User ID can only contain digits!");
  419. chk=0;
  420. getch();
  421. gotoxy(23,20);
  422. clreol();
  423. }
  424. }
  425. }
  426. }while(chk==0);
  427. do
  428. {
  429. chk=1;
  430. gotoxy(5,18);
  431. printf("Enter Address:");
  432. gets(customer_rec.address[x]);
  433. if(strlen(customer_rec.address[x])>40)
  434. {
  435. gotoxy(23,20);
  436. printf("User address must not be greater than 40 characters\n");
  437. chk=0;
  438. getch();
  439. gotoxy(23,20);
  440. clreol();
  441. }
  442. else if(strlen(customer_rec.address[x]) == 0)
  443. {
  444. gotoxy(23,20);
  445. printf("User address can not be unfilled");
  446. chk=0;
  447. getch();
  448. gotoxy(23,20);
  449. clreol();
  450. }
  451. }while(chk==0);
  452. do
  453. {
  454. ser1=strchr(customer_rec.email[x], ser); /*Statement to search for the character '@' from the entered string */
  455. ser2=strchr(customer_rec.email[x], ser0); /statement to search for the character '.' from the entered string/
  456. chk=1;
  457. gotoxy(5,20);
  458. clreol();
  459. printf("Enter e-mail address in small letters:");
  460. gets(customer_rec.email[x]);
  461. if(strlen(customer_rec.email[x])>15)
  462. {
  463. gotoxy(23,32);
  464. printf("User e-mail must not be greater than 15 characters\n");
  465. chk=0;
  466. getch();
  467. gotoxy(23,32);
  468. clreol();
  469. }
  470. else if(strlen(customer_rec.email[x]) == 0)
  471. {
  472. gotoxy(23,32);
  473. printf("User e-mail can not be left blank");
  474. chk=0;
  475. getch();
  476. gotoxy(23,32);
  477. clreol();
  478. }
  479. else if(ser1==NULL&&ser2==NULL)
  480. {
  481. gotoxy(23,32);
  482. printf("Enter a valid e-mail address!");
  483. chk=0;
  484. getch();
  485. gotoxy(23,32);
  486. clreol();
  487. }
  488. }while(chk==0);
  489. do
  490. {
  491. chk=1;
  492. gotoxy(5,22);
  493. printf("Enter telephone number:");
  494. gets(customer_rec.tel_num[x]);
  495. if(strlen(customer_rec.tel_num[x])>10)
  496. {
  497. gotoxy(23,32);
  498. printf("Telephone number must not be greater than 10 characters\n");
  499. chk=0;
  500. getch();
  501. gotoxy(23,32);
  502. clreol();
  503. }
  504. else if(strlen(customer_rec.tel_num[x]) == 0)
  505. {
  506. gotoxy(23,32);
  507. printf("User telephone number can not be left blank");
  508. chk=0;
  509. getch();
  510. gotoxy(23,32);
  511. clreol();
  512. }
  513. for(f=x;f<x+1;f++)
  514. {
  515. for(t=0;t<10;t++)
  516. {
  517. if(!isdigit(customer_rec.tel_num[f][t]))
  518. {
  519. gotoxy(23,32);
  520. printf("You entered an invalid value!");
  521. chk=0;
  522. getch();
  523. gotoxy(23,32);
  524. clreol();
  525. }
  526. }
  527. }
  528. }while(chk==0);
  529. gotoxy(24,32);
  530. clreol();
  531. printf("SAVE RECORD[Y/N]? ");
  532. scanf("%c",&save_rec);
  533. getchar();
  534. //fflush(stdin);
  535. if(save_rec=='y'||save_rec=='Y')
  536. {
  537. fwrite (&customer_rec,datsize, 1,ltlsys );
  538. }
  539. else
  540. {
  541. clrscr();
  542. menu();
  543. }
  544. clrscr();
  545. gotoxy(20,28);
  546. printf("\n\n\tWould you like to add another record[Y/N]:?");
  547. scanf("%c",&again1);
  548. getchar();
  549. clrscr();
  550. }
  551. if(again1=='n'||again1=='N')
  552. clrscr();
  553. menu();
  554. break;
  555. case 2:
  556. rewind(ltlsys);
  557. do
  558. {
  559. fread(&customer_rec,datsize,1,ltlsys);
  560. if(!feof(ltlsys))
  561. {
  562. gotoxy(1,1);
  563. printf("////////////////////////////////////////");
  564. printf("////////////////////////////////////////");
  565. printf("///////////////////////// LENNSVILLE LIBRARY");
  566. printf(" DATABASE //////////////////////////");
  567. printf("////////////////////////////////////////");
  568. printf("////////////////////////////////////////\n");
  569. printf("========================================");
  570. printf("========================================\n");
  571. gotoxy(1,6);
  572. printf("FIRST NAME");
  573. gotoxy(12,6);
  574. printf("LAST NAME");
  575. gotoxy(23,6);
  576. printf("ID ");
  577. gotoxy(28,6);
  578. printf("SEX ");
  579. gotoxy(32,6);
  580. printf("AGE");
  581. gotoxy(36,6);
  582. printf("DOJ");
  583. gotoxy(47,6);
  584. printf("ADDRESS");
  585. gotoxy(57,6);
  586. printf("E-MAIL");
  587. gotoxy(68,6);
  588. printf("TELEPHONE");
  589. printf("\n========================================");
  590. printf("========================================");
  591. if(trk==10)
  592. {
  593. gotoxy(80,20);
  594. printf("\n========================================");
  595. printf("========================================");
  596. gotoxy(28,23);
  597. printf("Please Enter To Continue");
  598. getch();
  599. trk=0;
  600. clrscr();
  601. }
  602. gotoxy(1,9+trk);
  603. printf("%s",customer_rec.f_name);
  604. gotoxy(12,9+trk);
  605. printf("%s",customer_rec.l_name);
  606. gotoxy(23,9+trk);
  607. printf("%s",customer_rec.id);
  608. gotoxy(28,9+trk);
  609. printf("%s",customer_rec.gender);
  610. gotoxy(32,9+trk);
  611. printf("%s",customer_rec.age);
  612. gotoxy(36,9+trk);
  613. printf("%s %s %s",customer_rec.dd,customer_rec.mth,customer_rec.yr);
  614. gotoxy(47,9+trk);
  615. printf("%s",customer_rec.address);
  616. gotoxy(62,9+trk);
  617. printf("%s",customer_rec.email);
  618. gotoxy(72,9+trk);
  619. printf("%s",customer_rec.tel_num);
  620. trk++;
  621. }
  622. }while(!feof(ltlsys));
  623. fclose(ltlsys);
  624. gotoxy(30,25+trk);
  625. printf("To return to the main menu, press enter..");
  626. getch();
  627. clrscr();
  628. menu();
  629. break;
  630. case 3:
  631. again1='Y';
  632. while(again1=='Y'||again1=='y')
  633. {
  634. gotoxy(30,8);
  635. printf("^^^^^^^^^^SEARCH MEMBER DATABASE^^^^^^^^^\n");
  636. printf("\n");
  637. printf("\t\tEnter first name to search member details: ");
  638. fflush(stdin);
  639. scanf("%s",fname2);
  640. rewind(ltlsys);
  641. while (fread(&customer_rec,datsize,1,ltlsys)==1)
  642. {
  643. if (strcmp(customer_rec.f_name,fname2)==0)
  644. {
  645. clrscr();
  646. gotoxy(12,1);
  647. printf("SEARCH RESULTS");
  648. gotoxy(12,2);
  649. printf("==============");
  650. gotoxy(12,3);
  651. printf("First name :");
  652. gotoxy(12,5);
  653. printf("Last name :");
  654. gotoxy(12,7);
  655. printf("ID :");
  656. gotoxy(12,9);
  657. printf("Gender :");
  658. gotoxy(12,11);
  659. printf("Age :");
  660. gotoxy(12,13);
  661. printf("D O J :");
  662. gotoxy(12,15);
  663. printf("Address :");
  664. gotoxy(12,17);
  665. printf("E-mail :");
  666. gotoxy(12,19);
  667. printf("Tel No. :");
  668. gotoxy(42,3);
  669. printf("%s",customer_rec.f_name);
  670. gotoxy(42,5);
  671. printf("%s",customer_rec.l_name);
  672. gotoxy(42,7);
  673. printf("%s",customer_rec.id);
  674. gotoxy(42,9);
  675. printf("%s",customer_rec.gender);
  676. gotoxy(42,11);
  677. printf("%s",customer_rec.age);
  678. gotoxy(42,13);
  679. printf("%s %s %s",customer_rec.dd,customer_rec.mth,customer_rec.yr);
  680. gotoxy(42,15);
  681. printf("%s",customer_rec.address);
  682. gotoxy(42,17);
  683. printf("%s",customer_rec.email);
  684. gotoxy(42,19);
  685. printf("%s",customer_rec.tel_num);
  686. }
  687. }
  688. gotoxy(30,28);
  689. printf("Do you want to search for another record[y/n]?:");
  690. fflush(stdin);
  691. scanf("%c",&again1);
  692. clrscr();
  693. }
  694. if(again1=='N'||again1=='n')
  695. fclose(ltlsys);
  696. clrscr();
  697. menu();
  698. break;
  699. case 4:
  700. again1='Y';
  701. while (again1=='y'||again1=='Y')
  702. {
  703. gotoxy(24,4);
  704. printf("^^^^^^^^^MODIFY LIBRARY RECORDS^^^^^^^^^^^");
  705. printf("\n");
  706. printf("Enter member first name to modify:");
  707. fflush(stdin);
  708. scanf("%s",fname2);
  709. rewind(ltlsys);
  710. while(fread(&customer_rec,datsize,1,ltlsys)==1)
  711. {
  712. if(strcmp(customer_rec.f_name,fname2)==0)
  713. {
  714. clrscr();
  715. gotoxy(35,4);
  716. printf(" MEMBER DETAILS");
  717. gotoxy(36,5);
  718. printf("==============");
  719. gotoxy(5,7);
  720. printf("First name :");
  721. gotoxy(5,9);
  722. printf("Last name :");
  723. gotoxy(5,11);
  724. printf("ID :");
  725. gotoxy(5,13);
  726. printf("Gender :");
  727. gotoxy(5,15);
  728. printf("Age :");
  729. gotoxy(5,17);
  730. printf("D O J :");
  731. gotoxy(5,19);
  732. printf("Address :");
  733. gotoxy(5,21);
  734. printf("E-mail :");
  735. gotoxy(5,23);
  736. printf("Tel No. :");
  737. gotoxy(17,7);
  738. printf("%s",customer_rec.f_name);
  739. gotoxy(17,9);
  740. printf("%s",customer_rec.l_name);
  741. gotoxy(17,11);
  742. printf("%s",customer_rec.id);
  743. gotoxy(17,13);
  744. printf("%s",customer_rec.gender);
  745. gotoxy(17,15);
  746. printf("%s",customer_rec.age);
  747. gotoxy(17,17);
  748. printf("%s %s %s",customer_rec.dd,customer_rec.mth,customer_rec.yr);
  749. gotoxy(17,19);
  750. printf("%s",customer_rec.address);
  751. gotoxy(17,21);
  752. printf("%s",customer_rec.email);
  753. gotoxy(17,23);
  754. printf("%s",customer_rec.tel_num);
  755. gotoxy(37,31);
  756. printf("1.Modify first name: ");
  757. gotoxy(37,33);
  758. printf("2.Modify last name :");
  759. gotoxy(37,35);
  760. printf("3.Modify ID :");
  761. gotoxy(37,37);
  762. printf("4.Modify gender :");
  763. gotoxy(37,39);
  764. printf("5.Modify Age :");
  765. gotoxy(37,41);
  766. printf("6.Modify D O J :");
  767. gotoxy(37,43);
  768. printf("7.Modify Address :");
  769. gotoxy(37,45);
  770. printf("8.Modify E-mail :");
  771. gotoxy(37,47);
  772. printf("9.Modify Tel No. :");
  773. gotoxy(37,49);
  774. printf("10.Quit without modification!");
  775. gotoxy(30,53);
  776. printf("Select item below to modify: ");
  777. scanf("%i",&choice2);
  778. getchar();
  779. switch(choice2)
  780. {
  781. case 1:
  782. fname();
  783. break;
  784. case 2:
  785. lname();
  786. break;
  787. case 3:
  788. id();
  789. break;
  790. case 4:
  791. gender();
  792. break;
  793. case 5:
  794. age();
  795. break;
  796. case 6:
  797. doj();
  798. break;
  799. case 7:
  800. address();
  801. break;
  802. case 8:
  803. email();
  804. break;
  805. case 9:
  806. tel_no();
  807. break;
  808. case 10:
  809. menu();
  810. break;
  811. default :
  812. {
  813. gotoxy(30,8);
  814. printf("Invalid choice, made please try again!");
  815. getch();
  816. clrscr();
  817. }
  818. break;
  819. }
  820. fseek(ltlsys,-datsize,SEEK_CUR);
  821. fwrite(&customer_rec,datsize,1,ltlsys);
  822. fclose(ltlsys);
  823. gotoxy(30,8);
  824. printf("\nDetails successfully modified.");
  825. }
  826. }
  827. printf("Would you like to modify another record?[Y/N]\n");
  828. again1=getche();
  829. clrscr();
  830. if(again1=='N'||again1=='n')
  831. clrscr();
  832. menu();
  833. }
  834. break;
  835. case 5:
  836. again1='Y';
  837. while(again1=='Y'|| again1=='y')
  838. {
  839. printf("Enter the first name of the member to be deleted: ");
  840. scanf("%s",fname2);
  841. tempdb=fopen("TEMP.DAT","wb");
  842. rewind(ltlsys);
  843. while(fread(&customer_rec,datsize,1,ltlsys)==1)
  844. {
  845. if(strcmp(customer_rec.f_name,fname2)!=0)
  846. {
  847. fwrite(&customer_rec,datsize,1,tempdb);
  848. }
  849. }
  850. fclose(ltlsys);
  851. fclose(tempdb);
  852. remove("LIBUSER.DAT");
  853. rename("TEMP.DAT","LIBUSER.DAT");
  854. ltlsys=fopen("LIBUSER.DAT","rb+");
  855. printf("Delete another Record(Y/N): ");
  856. fflush(stdin);
  857. again1=getchar();
  858. }
  859. break;
  860. case 6:
  861. {
  862. gotoxy(30,8);
  863. printf("Thank you for today!");
  864. printf("\n\t\t\tClosing database");
  865. for(d=1;d<10;d++)
  866. {
  867. printf(".");
  868. }
  869. fclose(ltlsys);
  870. exit(0);
  871. }
  872. break;
  873. default:
  874. {
  875. gotoxy(30,8);
  876. printf("You made an invalid request!");
  877. printf("\n\t\t\t\tPlease try again");
  878. getch();
  879. clrscr();
  880. menu();
  881. }
  882. break;
  883. }
  884. }
  885. }
  886. }
  887. }
  888. void menu(void) /menu function/
  889. {
  890. gotoxy(40,2);
  891. printf("\n\t\t\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  892. printf("\n\t\t^^^^ LENNSVILLE LIBRARY DATABASE SYSTEM ^^^^" );
  893. printf("\n\t\t\t MAIN MENU ");
  894. printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
  895. printf("\n\t\t\t1.Add library user records\n");
  896. printf("\n\t\t\t2.View library records\n");
  897. printf("\n\t\t\t3.Search library database\n");
  898. printf("\n\t\t\t4.Modify user records\n");
  899. printf("\n\t\t\t5.Delete library user details\n");
  900. printf("\n\t\t\t6.Exit system!");
  901. printf("\n");
  902. printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
  903. printf("\n\t\t\t Select Your Choice [1 - 6]: ");
  904. scanf("%i",&choice);
  905. getchar();
  906. clrscr();
  907. }
  908. void fname(void) /function for modifying first name of a member/
  909. {
  910. do
  911. {
  912. chk=1;
  913. gotoxy(5,6);
  914. printf("Enter new first name:");
  915. gets(customer_rec.f_name[x]);
  916. if(strlen(customer_rec.f_name[x])>12)
  917. {
  918. gotoxy(23,20);
  919. printf("New name must be less than 12 characters\n");
  920. chk=0;
  921. getch();
  922. gotoxy(23,20);
  923. clreol();
  924. }
  925. else if(strlen(customer_rec.f_name[x]) == 0)
  926. {
  927. gotoxy(23,20);
  928. printf("New name can not be left blank");
  929. chk=0;
  930. getch();
  931. gotoxy(23,20);
  932. clreol();
  933. }
  934. for(f=x;f<x+1;f++)
  935. {
  936. for(t=0;t<12;t++)
  937. {
  938. if(isdigit(customer_rec.f_name[f][t]))
  939. {
  940. gotoxy(23,20);
  941. printf("New first name can only have alphabets!");
  942. chk=0;
  943. getch();
  944. gotoxy(23,20);
  945. clreol();
  946. }
  947. }
  948. }
  949. }while(chk==0);
  950. }
  951. void lname(void) /function for modifying a member's last name/
  952. {
  953. do
  954. {
  955. chk=1;
  956. gotoxy(5,8);
  957. clreol();
  958. printf("Enter new last name:");
  959. gets(customer_rec.l_name[x]);
  960. if(strlen(customer_rec.l_name[x])>12)
  961. {
  962. gotoxy(23,20);
  963. printf("New last name must be less than 12 characters\n");
  964. chk=0;
  965. getch();
  966. gotoxy(23,20);
  967. clreol();
  968. }
  969. else if(strlen(customer_rec.l_name[x]) == 0)
  970. {
  971. gotoxy(23,20);
  972. printf("New last name must be filled");
  973. chk=0;
  974. getch();
  975. gotoxy(23,20);
  976. clreol();
  977. }
  978. for(f=x;f<x+1;f++)
  979. {
  980. for(t=0;t<12;t++)
  981. {
  982. if(isdigit(customer_rec.l_name[f][t]))
  983. {
  984. gotoxy(23,20);
  985. printf("New name can only contain alphabets!");
  986. chk=0;
  987. getch();
  988. gotoxy(23,20);
  989. clreol();
  990. }
  991. }
  992. }
  993. }while(chk==0);
  994. }
  995. void id(void) /function for modifying a member's ID/
  996. {
  997. do
  998. {
  999. chk=1;
  1000. gotoxy(5,16);
  1001. printf("Enter new ID No:");
  1002. gets(customer_rec.id[x]);
  1003. if(strlen(customer_rec.id[x])== 0)
  1004. {
  1005. gotoxy(23,20);
  1006. printf("New ID must be filled!\n");
  1007. chk=0;
  1008. getch();
  1009. gotoxy(23,20);
  1010. clreol();
  1011. }
  1012. else if(strcmp(customer_rec.id[x] ,"0000") == 0)
  1013. {
  1014. gotoxy(23,20);
  1015. printf("New ID value is invalid!");
  1016. chk=0;
  1017. getch();
  1018. gotoxy(23,20);
  1019. clreol();
  1020. }
  1021. for(f=x;f<x+1;f++)
  1022. {
  1023. for(t=0;t<4;t++)
  1024. {
  1025. if(!isdigit(customer_rec.id[f][t]))
  1026. {
  1027. gotoxy(23,20);
  1028. printf("New ID can only contain digits!");
  1029. chk=0;
  1030. getch();
  1031. gotoxy(23,20);
  1032. clreol();
  1033. }
  1034. }
  1035. }
  1036. }while(chk==0);
  1037. }
  1038. void gender(void) /function for modifying gender of a member/
  1039. {
  1040. do
  1041. {
  1042. chk=1;
  1043. gotoxy(5,12);
  1044. clreol();
  1045. printf("Enter new gender[M/F]:");
  1046. gets(customer_rec.gender[x]);
  1047. if(strlen(customer_rec.gender[x])==0)
  1048. {
  1049. gotoxy(23,20);
  1050. printf("New gender must be filled.\n");
  1051. chk=0;
  1052. getch();
  1053. gotoxy(23,20);
  1054. clreol();
  1055. }
  1056. else if(strlen(customer_rec.gender[x])>1)
  1057. {
  1058. gotoxy(23,20);
  1059. printf("Enter M for male or F for female");
  1060. chk=0;
  1061. getch();
  1062. gotoxy(23,20);
  1063. clreol();
  1064. }
  1065. }while(chk==0);
  1066. }
  1067. void age(void) /function for modifying a member's age/
  1068. {
  1069. do
  1070. {
  1071. chk=1;
  1072. gotoxy(5,10);
  1073. printf("Enter new age:");
  1074. gets(customer_rec.age[x]);
  1075. fflush(stdin);
  1076. if (strlen(customer_rec.age[x]) == 0)
  1077. {
  1078. gotoxy(20,23);
  1079. printf("New age can not be left blank");
  1080. chk=0;
  1081. getch();
  1082. gotoxy(20,23);
  1083. clreol();
  1084. }
  1085. else if (strlen(customer_rec.age[x])!=2)
  1086. {
  1087. gotoxy(20,23);
  1088. printf("New age must have 2 characters");
  1089. chk=0;
  1090. getch();
  1091. gotoxy(20,23);
  1092. clreol();
  1093. }
  1094. else if(strcmp(customer_rec.age[x],"00")==0)
  1095. {
  1096. gotoxy(20,23);
  1097. printf("New age value cannot be below 1 year");
  1098. chk=0;
  1099. getch();
  1100. gotoxy(20,23);
  1101. clreol();
  1102. }
  1103. for(f=x;f<x+1;f++)
  1104. {
  1105. for(t=0;t<2;t++)
  1106. {
  1107. if(!isdigit(customer_rec.age[f][t]))
  1108. {
  1109. gotoxy(20,23);
  1110. printf("New valid age value required!");
  1111. chk=0;
  1112. getch();
  1113. gotoxy(20,23);
  1114. clreol();
  1115. }
  1116. }
  1117. }
  1118. }while (chk==0);
  1119. }
  1120. void doj(void) /function for modifying a member's date of joining/
  1121. {
  1122. do
  1123. {
  1124. chk=1;
  1125. gotoxy(5,14);
  1126. clreol();
  1127. printf("Date of joining [dd mm yr]");
  1128. printf(" separated by a space: ");
  1129. scanf("%s %s %s",customer_rec.dd[x], customer_rec.mth[x], customer_rec.yr[x]);
  1130. fflush(stdin);
  1131. d = atof(customer_rec.dd[x]);
  1132. m = atof(customer_rec.mth[x]);
  1133. y = atof(customer_rec.yr[x]);
  1134. if (strlen(customer_rec.dd[x]) == 0)
  1135. {
  1136. gotoxy(20,23);
  1137. printf("New Day field must be filled");
  1138. chk=0;
  1139. getch();
  1140. gotoxy(20,23);
  1141. clreol();
  1142. }
  1143. else if (strlen(customer_rec.dd[x])!=2)
  1144. {
  1145. gotoxy(20,23);
  1146. printf("New Day field must have 2 characters");
  1147. chk=0;
  1148. getch();
  1149. gotoxy(20,23);
  1150. clreol();
  1151. }
  1152. else if(strcmp(customer_rec.dd[x],"00")==0)
  1153. {
  1154. gotoxy(20,23);
  1155. printf("New Day value cannot be below 1");
  1156. chk=0;
  1157. getch();
  1158. gotoxy(20,23);
  1159. clreol();
  1160. }
  1161. else if(d>31)
  1162. {
  1163. gotoxy(20,23);
  1164. printf("New Day value cannot be above 31");
  1165. chk=0;
  1166. getch();
  1167. gotoxy(20,23);
  1168. clreol();
  1169. }
  1170. else if (strlen(customer_rec.mth[x]) == 0)
  1171. {
  1172. gotoxy(20,23);
  1173. printf("New month field must be filled");
  1174. chk=0;
  1175. getch();
  1176. gotoxy(20,23);
  1177. clreol();
  1178. }
  1179. else if (strlen(customer_rec.mth[x])!=2)
  1180. {
  1181. gotoxy(20,23);
  1182. printf("New month field must have 2 characters!");
  1183. chk=0;
  1184. getch();
  1185. gotoxy(20,23);
  1186. clreol();
  1187. }
  1188. else if(strcmp(customer_rec.mth[x],"00")==0)
  1189. {
  1190. gotoxy(20,23);
  1191. printf("New month field cannot be below 1");
  1192. chk=0;
  1193. getch();
  1194. gotoxy(20,23);
  1195. clreol();
  1196. }
  1197. else if(m>12)
  1198. {
  1199. gotoxy(20,23);
  1200. printf("New month value should be less than 12");
  1201. chk=0;
  1202. getch();
  1203. gotoxy(20,23);
  1204. clreol();
  1205. }
  1206. else if (strlen(customer_rec.yr[x]) == 0)
  1207. {
  1208. gotoxy(20,23);
  1209. printf("New Year field must be filled");
  1210. chk=0;
  1211. getch();
  1212. gotoxy(20,23);
  1213. clreol();
  1214. }
  1215. else if (strlen(customer_rec.yr[x])!=4)
  1216. {
  1217. gotoxy(20,23);
  1218. printf("New Year field must be 4 characters!");
  1219. chk=0;
  1220. getch();
  1221. gotoxy(20,23);
  1222. clreol();
  1223. }
  1224. else if(y<1900)
  1225. {
  1226. gotoxy(20,23);
  1227. printf("New year cannot be below 1900 ");
  1228. chk=0;
  1229. getch();
  1230. gotoxy(20,23);
  1231. clreol();
  1232. }
  1233. }while(chk==0);
  1234. }
  1235. void address(void) /function for modifying the address of a member/
  1236. {
  1237. do
  1238. {
  1239. chk=1;
  1240. gotoxy(5,18);
  1241. printf("Enter new Address:");
  1242. gets(customer_rec.address[x]);
  1243. if(strlen(customer_rec.address[x])>40)
  1244. {
  1245. gotoxy(23,20);
  1246. printf("New address must be less than 40 characters\n");
  1247. chk=0;
  1248. getch();
  1249. gotoxy(23,20);
  1250. clreol();
  1251. }
  1252. else if(strlen(customer_rec.address[x]) == 0)
  1253. {
  1254. gotoxy(23,20);
  1255. printf("New address can not be blank");
  1256. chk=0;
  1257. getch();
  1258. gotoxy(23,20);
  1259. clreol();
  1260. }
  1261. }while(chk==0);
  1262. }
  1263. void email(void) /function for modifying the e-mail of a member/
  1264. {
  1265. do
  1266. {
  1267. ser1=strchr(customer_rec.email[x], '@');
  1268. ser2=strchr(customer_rec.email[x], '.');
  1269. chk=1;
  1270. gotoxy(5,20);
  1271. clreol();
  1272. printf("Enter new e-mail address in small letters:");
  1273. gets(customer_rec.email[x]);
  1274. if(strlen(customer_rec.email[x])>15)
  1275. {
  1276. gotoxy(23,24);
  1277. printf("New e-mail must be less than 15 characters\n");
  1278. chk=0;
  1279. getch();
  1280. gotoxy(23,24);
  1281. clreol();
  1282. }
  1283. else if(strlen(customer_rec.email[x]) == 0)
  1284. {
  1285. gotoxy(23,24);
  1286. printf("New e-mail can not be left blank");
  1287. chk=0;
  1288. getch();
  1289. gotoxy(23,24);
  1290. clreol();
  1291. }
  1292. else if(ser1==NULL&&ser2==NULL)
  1293. {
  1294. gotoxy(23,24);
  1295. printf("Enter a new valid e-mail address!");
  1296. chk=0;
  1297. getch();
  1298. gotoxy(23,24);
  1299. clreol();
  1300. }
  1301. }while(chk==0);
  1302. }
  1303. void tel_no(void) /function for modifying a member's telephone number/
  1304. {
  1305. do
  1306. {
  1307. chk=1;
  1308. gotoxy(5,22);
  1309. printf("Enter new telephone number:");
  1310. gets(customer_rec.tel_num[x]);
  1311. if(strlen(customer_rec.tel_num[x])>10)
  1312. {
  1313. gotoxy(23,24);
  1314. printf("New telephone number must be less than 10 characters\n");
  1315. chk=0;
  1316. getch();
  1317. gotoxy(23,24);
  1318. clreol();
  1319. }
  1320. else if(strlen(customer_rec.tel_num[x]) == 0)
  1321. {
  1322. gotoxy(23,24);
  1323. printf("New telephone number can not be left blank");
  1324. chk=0;
  1325. getch();
  1326. gotoxy(23,24);
  1327. clreol();
  1328. }
  1329. for(f=x;f<x+1;f++)
  1330. {
  1331. for(t=0;t<10;t++)
  1332. {
  1333. if(!isdigit(customer_rec.tel_num[f][t]))
  1334. {
  1335. gotoxy(23,24);
  1336. printf("New telephone number can only contain digits!");
  1337. chk=0;
  1338. getch();
  1339. gotoxy(23,24);
  1340. clreol();
  1341. }
  1342. }
  1343. }
  1344. }while(chk==0);
  1345. }

`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.