I made a program which adds , deletes and searches the contacts on the basis of their names. the add works file but the search function says "no record found" even if i enter a name which is present in the text file. am i wrong with the while syntax? can anyone help me fix the code? ive searched books and web the whole day and i still cant seem to debug it. any help would be much appreciated. the search records starts at line 131 . thank you! -
#include<stdio.h>
-
#include<conio.h>
-
#include<string.h>
-
#include<stdlib.h>
-
#include<ctype.h>
-
#define N 100
-
void addrecord();
-
void deleterecord(void);
-
void searchrecord(void);
-
void modifyrecord(void);
-
void viewrecord(void);
-
void mainmenu(void);
-
-
struct person{
-
char name[N],address[N],email[N];
-
long int citino,phone;
-
struct dob{
-
int dd,mm,yy;
-
}d;
-
};
-
char cho;
-
FILE *ptr;
-
-
int main()
-
{
-
void welcomeMessage();
-
mainmenu();
-
return 0;
-
}
-
void welcomeMessage()
-
{
-
system("COLOR 1F");
-
printf("\n\n\n\n\n");
-
printf("\n\t\t\t =============================================");
-
printf("\n\t\t\t | WELCOME |");
-
printf("\n\t\t\t | TO |");
-
printf("\n\t\t\t | RECORD |");
-
printf("\n\t\t\t | MANAGEMENT |");
-
printf("\n\t\t\t | SYSTEM |");
-
printf("\n\t\t\t =============================================");
-
printf("\n\n\n\t\t\t Enter any key to continue.....");
-
getch();
-
}
-
-
void mainmenu(void)
-
{
-
system("COLOR 6F");
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================");
-
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 --->");
-
int choice;
-
scanf("%d",&choice);
-
//we have to keep choices here
-
if(choice==1)
-
addrecord();
-
if(choice==3)
-
searchrecord();
-
-
-
if(choice==6)
-
{
-
system("COLOR 4F");
-
system("cls");
-
printf("\n\n");
-
printf(" A project by:\n\n");
-
-
printf("\n\n");
-
printf(" *******************************THANK YOU**************************************\n");
-
getch();
-
mainmenu();
-
}
-
-
-
-
if(choice==7){
-
system("COLOR 4F");
-
system("cls");
-
printf("\n\n\n");
-
printf(" *******************************THANK YOU**************************************\n");
-
}
-
}
-
//we have to keep choices here
-
-
void addrecord()
-
{
-
char back1,back2;
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================\n\n\n");
-
label:
-
ptr=fopen("C:\\Users\\Astha\\Downloads\\record.txt","a");
-
struct person a;
-
fflush(stdin);
-
printf("Enter name:");
-
gets(a.name);
-
fflush(stdin);
-
printf("Enter address:");
-
gets(a.address);
-
fflush(stdin);
-
printf("Enter email:");
-
gets(a.email);
-
fflush(stdin);
-
printf("Enter citizenship number:");
-
scanf("%ld",&a.citino);
-
printf("Enter phone:");
-
scanf("%ld",&a.phone);
-
printf("Enter date of birth in dd/mm/yy:");
-
scanf("%d%c%d%c%d",&a.d.dd,&back1,&a.d.mm,&back2,&a.d.yy);
-
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);
-
fclose(ptr);
-
fflush(stdin);
-
printf("Would you like to enter more records:(y/n)\n");
-
printf("Enter choice:");
-
fflush(stdin);
-
scanf("%c",&cho);
-
if(cho=='y'||cho=='Y')
-
{
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================\n\n\n");
-
goto label;
-
}
-
else if(cho=='n' || cho=='N')
-
mainmenu();
-
-
}
-
void searchrecord()
-
{
-
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================\n\n\n");
-
label:
-
FILE*f;
-
f=fopen("C:\\Users\\Astha\\Downloads\\record.txt","r");
-
-
-
int flag=0;
-
struct person e;
-
if(f==NULL)
-
{
-
printf("\n error in opening\a\a\a\a");
-
exit(0);
-
-
}
-
-
char s[100];
-
-
-
printf(" Enter Name :");
-
scanf("%s",s);
-
fflush(stdin);
-
-
while(!feof(f) && flag==0)
-
{
-
-
if((strcmp(e.name,s))==0) //checks whether a.name is equal to s or not
-
{
-
flag=1;
-
printf(" .........................The Record is available...........................\n\n\n");
-
-
printf(" Name : %s\n\n",e.name);
-
printf(" Date OF Birth :%d/%d/%d\n\n",e.d.dd,e.d.mm,e.d.yy);
-
printf(" \n Address : %s",e.address);
-
printf(" \n Email : %s",e.email);
-
printf(" \n Citizenship number : %ld ",e.citino);
-
printf(" \n Phone : %ld",e.phone);
-
}
-
}
-
if (flag==0)
-
printf("\n aNo Record Found\a");
-
-
-
-
-
printf("\n\n");
-
-
-
-
fclose(f);
-
fflush(stdin);
-
printf("\nWould you like to enter more records:(y/n)\n");
-
printf("Enter choice:");
-
-
scanf("%c",&cho);
-
if(cho=='y'||cho=='Y')
-
{
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================\n\n\n");
-
goto label;
-
}
-
else if(cho=='n' || cho=='N')
-
mainmenu();
-
-
}
-
-
1 2775
I made a program which adds , deletes and searches the contacts on the basis of their names. the add works file but the search function says "no record found" even if i enter a name which is present in the text file. am i wrong with the while syntax? can anyone help me fix the code? ive searched books and web the whole day and i still cant seem to debug it. any help would be much appreciated. the search records starts at line 131 . thank you! - void searchrecord()
-
{
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================\n\n\n");
-
label:
-
FILE * f;
-
f = fopen("C:\\Users\\Astha\\Downloads\\record.txt", "r");
-
-
int flag = 0;
-
struct person e;
-
if (f == NULL)
-
{
-
printf("\n error in opening\a\a\a\a");
-
exit(0);
-
-
}
-
-
char s[100];
-
-
printf(" Enter Name :");
-
scanf("%s", s);
-
fflush(stdin);
-
-
while (!feof(f) && flag == 0)
-
{
-
if ((strcmp(e.name, s)) == 0) //checks whether a.name is equal to s or not
-
{
-
flag = 1;
-
printf(" .........................The Record is available...........................\n\n\n");
-
-
printf(" Name : %s\n\n", e.name);
-
printf(" Date OF Birth :%d/%d/%d\n\n", e.d.dd, e.d.mm, e.d.yy);
-
printf(" \n Address : %s", e.address);
-
printf(" \n Email : %s", e.email);
-
printf(" \n Citizenship number : %ld ", e.citino);
-
printf(" \n Phone : %ld", e.phone);
-
}
-
}
-
-
if (flag == 0)
-
printf("\n aNo Record Found\a");
-
-
printf("\n\n");
-
-
fclose(f);
-
fflush(stdin);
-
printf("\nWould you like to enter more records:(y/n)\n");
-
printf("Enter choice:");
-
-
scanf("%c", &cho);
-
if (cho == 'y' || cho == 'Y')
-
{
-
system("cls");
-
printf(" ============================================\n");
-
printf(" | RECORD MANAGEMENT SYSTEM | \n");
-
printf(" ============================================\n\n\n");
-
goto label;
-
}
-
else if (cho == 'n' || cho == 'N')
-
mainmenu();
-
-
}
I see no code that reads the data from the file to the structure variable.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rizwan |
last post by:
I have the following tasks :
1) receive a flat text file which contains data and
2) convert it into an XML
The flat text file for example is in this format :
1 2...
|
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"));...
|
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...
|
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...
|
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...
|
by: ashu0720 |
last post by:
how to convert text file into image file in VC++
|
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...
|
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...
|
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...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |