address book

This is a discussion on address book within the C Programming forums, part of the General Programming Boards category; Hi yoo i am almost finished with the address book .I am having problem with my search function which i ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    Talking 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
    Attached Files Attached Files
    Last edited by datainjector; 11-28-2002 at 06:46 PM.
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>I am having problem with my search function
    Can you describe the problem please.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    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.
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    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
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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<
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    hey thanks alot man...Yeah now my search function is working when i am finished i will post it ...Thanks alot
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 12:29 PM
  2. Replies: 10
    Last Post: 09-04-2008, 02:27 PM
  3. simple structure/linked list question
    By niponki in forum C Programming
    Replies: 16
    Last Post: 08-15-2005, 12:13 AM
  4. Memory leak - need help finding
    By ChadJohnson in forum C++ Programming
    Replies: 8
    Last Post: 04-06-2005, 08:26 PM
  5. Books on C and C++
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-28-2002, 04:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21