phonebook

This is a discussion on phonebook within the C Programming forums, part of the General Programming Boards category; this program is phone book.. it supposed to edit, enter, delet entries.. but.. when I compile, it gives these messages ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    phonebook

    this program is phone book..
    it supposed to edit, enter, delet entries..
    but..
    when I compile, it gives these messages

    strucructure.c.c: In function `deleteentry':
    strucructure.c.c:137: warning: passing arg 1 of `searchbook' from incompatible pointer type
    strucructure.c.c: In function `editentry':
    strucructure.c.c:147: warning: passing arg 1 of `searchbook' from incompatible pointer type
    strucructure.c.c:148: warning: passing arg 1 of `newentry' makes pointer from integer without a cast
    strucructure.c: undefined reference to `listbook'

    I try to fix it, but it still gives me these warnings and error messages.

    Code:
    #include <stdio.h>
    
    struct entry
    {
    	char name[30];
    	char phoneNo[12];
    	char email[20];
    };
    
    struct entry addressbook[100];
    int addresssize = 100;
    
    char newentry(struct entry *input, int i);
    char getinput(struct entry *input);
    void deleteentry(struct entry *input);
    void editentry(struct entry *input);
    int searchbook(struct entry *input);
    int srarch(char n[30]);
    void listphonebook(struct entry *input);
    void menu();
    
    
    main()
    {
    
    
    char menusel;
    int i = 1;
    int counter = 0;
    
    	do
    	{ 
    		
    	scanf("%c", &menusel);
     
    		switch(menusel)
    		{ 
    			case '1': 
    			newentry(addressbook, counter);
    			break;
     
    			case '2': 
    			deleteentry(addressbook);
    			break; 
    	
    			case '3': 
    			editentry(addressbook);
    			break; 
    
    			case '4': 
    			searchbook(addressbook);
    			break; 
    		
    			case '5': 
    			listbook(addressbook); 
    			break; 
    
    			case '6': 
    			i=2; 
    		} 
    	
    	}while(i<=1); 
    }
    
    void menu()
    {
    
    	printf("1. Add a new entry\n");
    	printf("2. Delete an entry\n");
    	printf("3. Edit an entry\n");
    	printf("4. Search Phone Book\n");
    	printf("5. List Phone Book\n");
    	printf("6. Quit\n");
    	printf("Select menu: \n");
    }
    
    
    char newentry(struct entry *input, int i)
    {
    
    int inputcheck;
    int inputcheck2;
    int inputcheck3;
    
    	printf("Please Enter a name: ");
    	inputcheck = scanf("%c", &input[i].name);
    
    	if(inputcheck ==0 )
    	{
    	printf("Please Enter a name: ");
    	inputcheck = scanf("%c", &input[i].name);
    	}
    
    	printf("Please Enter a phone number: ");
    	inputcheck2 = scanf("%c", &input[i].phoneNo);	
    
    	if(inputcheck2 ==0 )
    	{
    	printf("Please Enter a phone number: ");
    	inputcheck2 = scanf("%c", &input[i].phoneNo);
    	}
    
    	printf("Please Enter e-mail address: ");
    	inputcheck3 = scanf("%c", &input[i].email);
    
    	if(inputcheck3 ==0 )
    	{
    	*input[i].email = ' ';
    	}
    	
    }
    
    char getinput(struct entry *input)
    {
    int inputcheck4;
    char name2[30];
    	
    	printf("Please Enter a name: ");
    	inputcheck4 = scanf("%c", &name2);
    
    	if(inputcheck4 ==0 )
    	{
    	printf("Please Enter a name: ");
    	inputcheck4 = scanf("%c", &name2);
    	
    	}
    	return ;
    	
    }
    
    void deleteentry(struct entry *input)
    {
    int index;
    char storedname[30];
    
    storedname[30] = getinput(input);
    index = searchbook(storedname);	
    addressbook[index] = addressbook[addresssize - 1];
    }
    
    void editentry(struct entry *input)
    {
    char findname[30];
    int index;
    
     findname[30] = getinput(input);
     index = searchbook(findname);
     newentry(findname[30], index);
    
    }
    
    int searchbook(struct entry *input)
    {
    int num;
    char getname[30];
    
    getname[30] = getinput(input);
    num = search(getname);
    return num;
    
    }
    
    int search(char n[30])
    {
    int i;
    
    	for (i=0; i< addresssize -1; ++i)
    	{
    		if (n== addressbook[i].name)
    		{
    		return i;
    		}		
    		else
    		{
    		return -1;
    		}
    	}
    }
    
    
    
    
    void listphonebook(struct entry *input)
    {
    int i=0;
    
    	while (i<=100)
    	{
    		printf("%c ", addressbook[i].name);
    		printf("%c ", addressbook[i].phoneNo);
    		printf("%c \n", addressbook[i].email);
    		i++;
    	}
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    char storedname[30];

    storedname[30] = getinput(input);
    index = searchbook(storedname);

    int searchbook(struct entry *input)
    Now do you see the problem? You have the exact same problem with your 'newentry' errors. You keep passing strings when you should be passing pointers to structures.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    it doesn't take input

    now this program runs..
    but it does't take any inputs.
    can you tell me how to fix it?

    Code:
    #include <stdio.h>
    
    struct entry
    {
    	char name[30];
    	char phoneNo[12];
    	char email[20];
    };
    
    struct entry addressbook[100];
    int addresssize = 100;
    
    char newentry(struct entry *input, int i);
    char getinput(struct entry *input);
    void deleteentry(struct entry *input);
    void editentry(struct entry *input);
    int searchbook(struct entry *input);
    int srarch(char n[30]);
    void listphonebook(struct entry *input);
    void menu();
    
    
    main()
    {
    
    
    char menusel;
    int i = 1;
    int counter = 0;
    
    	do
    	{ 
    
    	menu();
    	scanf("%c", &menusel);
     
    		switch(menusel)
    		{ 
    			case '1': 
    			newentry(addressbook, counter);
    			break;
     
    			case '2': 
    			deleteentry(addressbook);
    			break; 
    	
    			case '3': 
    			editentry(addressbook);
    			break; 
    
    			case '4': 
    			searchbook(addressbook);
    			break; 
    		
    			case '5': 
    			listphonebook(addressbook);
    			break; 
    
    			case '6': 
    			i=2; 
    		} 
    	
    	}while(i<=1); 
    }
    
    void menu()
    {
    
    	printf("1. Add a new entry\n");
    	printf("2. Delete an entry\n");
    	printf("3. Edit an entry\n");
    	printf("4. Search Phone Book\n");
    	printf("5. List Phone Book\n");
    	printf("6. Quit\n");
    	printf("Select menu: \n");
    }
    
    
    char newentry(struct entry *input, int i)
    {
    
    int inputcheck;
    int inputcheck2;
    int inputcheck3;
    
    	printf("Please Enter a name:\n ");
    	inputcheck = scanf("%c", &input[i].name);
    
    	if(inputcheck ==0 )
    	{
    	printf("Please Enter a name: \n");
    	inputcheck = scanf("%c", &input[i].name);
    	}
    
    	printf("Please Enter a phone number:\n ");
    	inputcheck2 = scanf("%c", &input[i].phoneNo);	
    
    	if(inputcheck2 ==0 )
    	{
    	printf("Please Enter a phone number:\n ");
    	inputcheck2 = scanf("%c", &input[i].phoneNo);
    	}
    
    	printf("Please Enter e-mail address:\n ");
    	inputcheck3 = scanf("%c", &input[i].email);
    
    	if(inputcheck3 ==0 )
    	{
    	*input[i].email = ' ';
    	}
    	
    }
    
    char getinput(struct entry *input)
    {
    int inputcheck4;
    char name2[30];
    	
    	printf("Please Enter a name:\n ");
    	inputcheck4 = scanf("%c", &name2);
    
    	if(inputcheck4 ==0 )
    	{
    	printf("Please Enter a name:\n ");
    	inputcheck4 = scanf("%c", &name2);
    	
    	}
    	return name2[30];
    	
    }
    
    void deleteentry(struct entry *input)
    {
    int index;
    char storedname[30];
    
    storedname[30] = getinput(input);
    index = searchbook(storedname);	
    addressbook[index] = addressbook[addresssize - 1];
    }
    
    void editentry(struct entry *input)
    {
    char findname[30];
    int index;
    
     findname[30] = getinput(input);
     index = searchbook(findname[30]);
     newentry(findname[30], index);
    
    }
    
    int searchbook(struct entry *input)
    {
    int num;
    char getname[30];
    
    getname[30] = getinput(input);
    num = search(getname[30]);
    return num;
    
    }
    
    int search(char n[30])
    {
    int i;
    
    	for (i=0; i< addresssize -1; ++i)
    	{
    		if (n[30]== addressbook[i].name)
    		{
    		return i;
    		}		
    		else
    		{
    		return -1;
    		}
    	}
    }
    
    
    
    
    void listphonebook(struct entry *input)
    {
    int i=0;
    
    	while (i<=100)
    	{
    		printf("%c ", input[i].name);
    		printf("%c ", input[i].phoneNo);
    		printf("%c \n", input[i].email);
    		++i;
    	}
    }

  4. #4
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    use code tags

    edit: nevermind you edited them in
    hello, internet!

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here's a few things:

    1) Why does this function return a char? You never have it return anything.

    char newentry(struct entry *input, int i)

    2) storedname[30] = getinput(input);

    This is entirely incorrect, for three reasons:
    a) 30 is out of the bounds of your array.
    b) getinput( ) isn't at all working how you expect
    c) This doesn't copy a string from getinput( ) to the array.

    3) getinput( ) is wrong. Period.

    This function does not return a string. What it does return is a single character outside the bounds of the array you declare in the function. Bad.

    4) Stop doing this:

    newentry(findname[30], index);

    When you're passing an array to a function, all you need to do is pass the name of the array. If you specify a single element, which is what you're doing in the line above, make sure it's actually in the bounds of your array.

    ALL arrays contain elements numbering from 0 to SIZE-1. This means:

    int array[45];

    The valid bounds of this array are anywhere from:

    array[0]

    To:

    array[44]

    This is outside the bounds of your array:

    array[45]

    This points to some memory address past the end of the array, and god only knows what's there.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    how can I use getinput to return a string or something?

    even though my getinput() doesn't return anything..
    still how come scanf doesn't take input from user?

    same for newentry function..

    onlything works fine is #6 quit the program..
    Last edited by jk81; 09-24-2002 at 11:22 PM.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Another one for the pot:
    >>inputcheck4 = scanf("%c", &name2);
    %c inputs a single char.
    name2 is already a pointer (in disguise), so you don't need &.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding nodes to a linked list
    By bluescreen in forum C Programming
    Replies: 4
    Last Post: 11-09-2006, 01:59 AM
  2. phonebook help
    By noob2c in forum C Programming
    Replies: 5
    Last Post: 04-19-2003, 02:51 PM
  3. Linked list question....again
    By dP munky in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2003, 05:59 PM
  4. phonebook error
    By cguy in forum C Programming
    Replies: 2
    Last Post: 01-30-2003, 01:08 AM
  5. What am I doing wrong?
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-26-2003, 11:39 PM

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