Originally Posted by
enjoyincubus
@quzah
ive read what youve wrote
if you mean the data that are being ask by the user , i already have them
it works w/ view function
Yeah, so? You're not even remotely paying attention to what your code does.
Originally Posted by
enjoyincubus
it will result into an "Error: Record not found"
here is my code again:
Of course it does. It'd be ........ing miracle if it actually worked. I don't even want to attempt to calculate the odds on that working right. I'll comment your code, since you apparently have no idea what you're doing.
Code:
void search (void) /* first, you're not passing any arguments... */
{
FILE *fp;
contact_rec X[4]; /* declare a local array, which holds nothing right now... */
char s;
int i = 0;
if ((fp = fopen ("phone.dat", "rb")) == NULL) /* open the file for reading... */
{
printf ("Error : file is does not exist");
exit(1);
}
printf ("Enter a name to be search: ");
fgets(&s, sizeof(contact_rec), stdin); /* get something to search for... */
for ( i = 0; i < 5; i++)
{
/* look through the array, which contains nothing useful... */
if ((strcmp (&s, X[i].name)) == 0)
{
printf("%s", X[i].tel);
printf("%s", X[i].cel);
}
else
{
/* somehow be mystified as to why it doesn't work... */
printf("Error : Record not found");
fclose(fp);
}
}
/* return without closing the file, since you only close it on error... */
}
Like I said, you never actually read. Well that's actually really really apparent. You never actually read what I write, and you never actually read anything from your file here, just like I keep saying!
Quzah.