-
address book
Hi yoo i am almost finished with the address book .I am having problem with my search function which i dont know whats wrong with it......The code is a big long 1000 lines over .Any comments plzzz and yeah if u find any bugs plzz to report .And yeah one more thing on windows 2000 the layout of my address book get freaked up ..why ?? /*Edit its also print a t character 't' before the phone number why...
*/
Thanks
-
>>I am having problem with my search function
Can you describe the problem please.
-
Well i used a struc type array[] I took in all the entries from the file and stored it in a strct array[] then used the string.h function to creat a search option..Well i think it isnt searching it at all.It does not diaplay anything.i used 2 types of search one is u can use a wildcard lik kar* so it will find the names or last name etc that start witn kar or just the name.
-
>>while ( !feof( exPtr ))
This is the incorrect way to control the loop. Use the return code from fread(). Also, you'll need to open the files in binary mode.
Code:
if ( select == 'n')
{
if ( sub_select == 'f')
{
if ( wildcard(input) == 1) /* wildcard e.g kar* */
{
while ( ++cnt <= datasize )
{
for (i = 0; i <=num; i++ )
{
if ( strncmp(Data[i....
This is way too nested, imho. It makes things too hard to follow.
>>i+=i;
>>num = i+ num;
I have no idea what you're planning here. A few comments in the source would help!
How much of this have you actually debugged? If you don't have a debugger, stick some printf()'s in appropriate places in the code to checkpoint it.
-
Return value you mean if its zero its an error ???? Yeah i used the inner for loop to display 4 record then if button pressed clr and diplay the other records .Why do i have to open it in binary mode.What i have heard and read is that binary mode is non-portable so why should i use it. And yeah the search function its taking in the values from the file to the struct array with no problem but i cant still find the bug.
Thanks alot
-
>>Return value you mean if its zero its an error ????
Look:
Code:
while (fread(&Data, sizeof( struct data), 1, dPtr) == 1)
{
/* Process data */
}
>>Why do i have to open it in binary mode
Because you're writing structures. And yes, it is standard C.
>>fflush(stdin);
Come on, you know better than that!
... and the problem with the search facility is.... you are using fgets() to get the input data in the first place, and scanf() to get the search criteria. If you don't know what's wrong with doing this and what problems it causes, I suggest you do a board search ;)
Also, you have some serious problems with going outside array bounds:
Code:
while ( ++cnt <= datasize )
{
fprintf (fpdebug, "Start of for loop\n");
for (i = 0; i <=num; i++ )
{
fprintf (fpdebug, "Comp: >%s< >%s<\n", Data[i].firstname, input );
if ( strcmp(Data[i].firstname, input ) == 0 )
{
printf("%s%s%s%s", Data[i].firstname, Data[i].lastname, Data[i].address, Data[i].phone);
}
}
i+=i;
num = i+ num;
gotoxy(1,25);
cprintf("Press <return> to continue....");
getch();
}
The above code has two debug lines I added to write out some variables to see what was going on. My phone book had only one record in it, so I was mildly suprised when I found that the loops had checked a few more records than the one:
Code:
Start of for loop
Comp: >hammer< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Start of for loop
Comp: >hammer< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
Comp: >< >hammer<
-
hey thanks alot man...Yeah now my search function is working when i am finished i will post it ...Thanks alot