472,354 Members | 1,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

C text file for storing and searching file

This is my code for the program. however the search section does not seem to be working, no matter even if the name is present in the file it still shows not found. is my syntax for while wrong? ive been trying to debug this for the whole day and i still cant fix it. :c please help
the problem is in searchrecord () function starting from line 130
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<ctype.h>
  6. #define N 100
  7. void addrecord();
  8. void deleterecord(void);
  9. void searchrecord(void);
  10. void modifyrecord(void);
  11. void viewrecord(void);
  12. void mainmenu(void);
  13.  
  14. struct person{
  15. char name[N],address[N],email[N];
  16. long int citino,phone;
  17. struct dob{
  18. int dd,mm,yy;
  19. }d;
  20. };
  21. char cho;
  22. FILE *ptr;
  23.  
  24. int main()
  25. {
  26.     void welcomeMessage();
  27.     mainmenu();
  28.     return 0;
  29. }
  30. void welcomeMessage()
  31. {
  32.     system("COLOR 1F");
  33.     printf("\n\n\n\n\n");
  34.     printf("\n\t\t\t        =============================================");
  35.     printf("\n\t\t\t        |                  WELCOME                  |");
  36.     printf("\n\t\t\t        |                    TO                     |");
  37.     printf("\n\t\t\t        |                  RECORD                   |");
  38.     printf("\n\t\t\t        |                 MANAGEMENT                |");
  39.     printf("\n\t\t\t        |                   SYSTEM                  |");
  40.     printf("\n\t\t\t        =============================================");
  41.     printf("\n\n\n\t\t\t Enter any key to continue.....");
  42.     getch();
  43. }
  44.  
  45. void mainmenu(void)
  46. {
  47.     system("COLOR 6F");
  48.     system("cls");
  49.     printf("                                       ============================================\n");
  50.     printf("                                       |           RECORD MANAGEMENT SYSTEM       | \n");
  51.     printf("                                       ============================================");
  52.     printf("\n\n\n          [1] ADD RECORDS--> \n\n          [2] VIEW RECORDS--> \n\n          [3] SEARCH RECORDS--> \n\n          [4] DELETE RECORDS--> \n\n          [5] MODIFY RECORDS-->\n\n          [6] ABOUT US--> \n\n          [7] EXIT--> \n\n\n             Enter Your Choice --->");
  53.     int choice;
  54.     scanf("%d",&choice);
  55.     //we have to keep choices here
  56.     if(choice==1)
  57.         addrecord();
  58.             if(choice==3)
  59.         searchrecord();
  60.  
  61.  
  62.         if(choice==6)
  63.         {
  64.         system("COLOR 4F");
  65.         system("cls");
  66.         printf("\n\n");
  67.         printf("        A project by:\n\n");
  68.  
  69.         printf("                         *******************************THANK YOU**************************************\n");
  70.         getch();
  71.         mainmenu();
  72.         }
  73.  
  74.  
  75.  
  76.         if(choice==7){
  77.         system("COLOR 4F");
  78.         system("cls");
  79.         printf("\n\n\n");
  80.         printf("                         *******************************THANK YOU**************************************\n");
  81.         }
  82. }
  83.     //we have to keep choices here
  84.  
  85. void addrecord()
  86. {
  87.     char back1,back2;
  88.     system("cls");
  89.     printf("                                       ============================================\n");
  90.     printf("                                       |           RECORD MANAGEMENT SYSTEM       | \n");
  91.     printf("                                       ============================================\n\n\n");
  92.     label:
  93.     ptr=fopen("C:\\Users\\Astha\\Downloads\\record.txt","a");
  94.     struct person a;
  95.     fflush(stdin);
  96.     printf("Enter name:");
  97.     gets(a.name);
  98.     fflush(stdin);
  99.     printf("Enter address:");
  100.     gets(a.address);
  101.     fflush(stdin);
  102.     printf("Enter email:");
  103.     gets(a.email);
  104.     fflush(stdin);
  105.     printf("Enter citizenship number:");
  106.     scanf("%ld",&a.citino);
  107.     printf("Enter phone:");
  108.     scanf("%ld",&a.phone);
  109.     printf("Enter date of birth in dd/mm/yy:");
  110.     scanf("%d%c%d%c%d",&a.d.dd,&back1,&a.d.mm,&back2,&a.d.yy);
  111.     fprintf(ptr,"%-30s %-20s %-30s %-20d %-15d %d/%d/%d\n",a.name,a.address,a.email,a.citino,a.phone,a.d.dd,a.d.mm,a.d.yy);
  112.     fclose(ptr);
  113.     fflush(stdin);
  114.     printf("Would you like to enter more records:(y/n)\n");
  115.     printf("Enter choice:");
  116.     fflush(stdin);
  117.     scanf("%c",&cho);
  118.     if(cho=='y'||cho=='Y')
  119.     {
  120.     system("cls");
  121.     printf("                                       ============================================\n");
  122.     printf("                                       |           RECORD MANAGEMENT SYSTEM       | \n");
  123.     printf("                                       ============================================\n\n\n");
  124.         goto label;
  125.     }
  126.     else if(cho=='n' || cho=='N')
  127.     mainmenu();
  128.  
  129. }
  130. void searchrecord()
  131. {
  132.  
  133.     system("cls");
  134.     printf("                                       ============================================\n");
  135.     printf("                                       |           RECORD MANAGEMENT SYSTEM       | \n");
  136.     printf("                                       ============================================\n\n\n");
  137.     label:
  138.     FILE*f;    
  139.    f=fopen("C:\\Users\\Astha\\Downloads\\record.txt","r");
  140.  
  141.  
  142. int flag=0;
  143. struct person e;
  144. if(f==NULL)
  145. {
  146.     printf("\n error in opening\a\a\a\a");
  147.     exit(0);
  148.  
  149. }
  150.  
  151.         char s[100];
  152.  
  153.  
  154.         printf("  Enter  Name :");
  155. scanf("%s",s);
  156.  fflush(stdin);
  157.  
  158.       while(!feof(f) && flag==0)
  159.     {
  160.  
  161.         if((strcmp(e.name,s))==0) //checks whether a.name is equal to s or not
  162.         {
  163.             flag=1;
  164.             printf("                               .........................The Record is available...........................\n\n\n");
  165.  
  166.             printf("       Name : %s\n\n",e.name);
  167.             printf("       Date OF Birth :%d/%d/%d\n\n",e.d.dd,e.d.mm,e.d.yy);
  168.              printf(" \n Address : %s",e.address);
  169.                           printf(" \n Email : %s",e.email);
  170.                           printf(" \n Citizenship number : %ld ",e.citino);
  171.                                  printf(" \n Phone : %ld",e.phone);
  172.         }
  173.     }
  174.         if (flag==0)
  175.         printf("\n aNo Record Found\a");
  176.  
  177.  
  178.  
  179.  
  180.         printf("\n\n");
  181.  
  182.  
  183.  
  184.     fclose(f);
  185.     fflush(stdin);
  186.     printf("\nWould you like to enter more records:(y/n)\n");
  187.     printf("Enter choice:");
  188.  
  189.     scanf("%c",&cho);
  190.     if(cho=='y'||cho=='Y')
  191.     {
  192.     system("cls");
  193.     printf("                                       ============================================\n");
  194.     printf("                                       |           RECORD MANAGEMENT SYSTEM       | \n");
  195.     printf("                                       ============================================\n\n\n");
  196.         goto label;
  197.     }
  198.     else if(cho=='n' || cho=='N')
  199.     mainmenu();
  200.  
  201. }
Aug 17 '21 #1
0 838

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: cwbp15 | last post by:
Using Visual Studio C# When I ran the following code: System.IO; private void Button1_Click(object sender, System.EventArgs e) { //FileStream fs = File.Create(Server.MapPath("test.txt"));...
3
by: C# to XML | last post by:
Hi Friends, I am new to csharp , I am using the following code to write into xml file : Just go through the code : fp = File.OpenText(Server.MapPath(".\\upload\\") + "test.txt"); string...
2
by: ahynes | last post by:
HI folks, I'm a chem engineer with no VB programming knowledge (as you'll see from my question!) I want a script to open a .txt file, insert pre-defined text into the start and end of the...
9
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all...
1
by: ashu0720 | last post by:
how to convert text file into image file in VC++
2
by: jld730 | last post by:
Greetings! I am still new to Python, sorry! I have been searching through many posts on this subject and have attempted to TRY, but I feel really lost. So, any detailed guidance would be oh-so...
2
by: progvar | last post by:
Hi! can any one help me by providing the method when i open any text file and convert into pdf format. I searched on the net and i got some code but i am not understanding this code and it also...
1
by: agarwalsunitadhn | last post by:
Hi I am developing an application in which i need to convert a text file into a resource file and then serach different resources from the resource file. I want to know how to create the resource...
2
by: pulavarthipraveen | last post by:
Overview: We have a requirement in the c#.NET 1.0 windows application. There will be some input text file in the user’s machine. The user should browse and select the input text file and also select...
13
by: madankarmukta | last post by:
Hi all, Is there any way by which I can export the data from the dataset table to the text file or xls file ? Currently I implemented this by itterating through each row of the table and...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.