Thread: Can't Return/Assign Char Pointer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    26

    Can't Return/Assign Char Pointer

    Hey Folks,

    I'm getting an "incompatible types in assignment" error and warning as well as a "return makes pointer from integer without cast" warning. Yes, I'm a newb. I've been reading the tutorials here and on other sites as well as K & R but I still haven't been able to get this code straigtened out. I want to return the contents of the pointer to char array from each call to get_input to the specified part of the structure in input (). Thanks for reading.

    Code:
    contact input ();
    char* get_input (char[26], int);
    Code:
    contact input ()                                                /* gets an entry from the user */
    {
         contact entry = {'\0','\0','\0','\0','\0','\0','\0','\0'}; /* initializes the structure   */
         char prompt1[26] = "Please enter a new name.";
         char prompt2[26] = "Enter a street address.";
         char prompt3[26] = "Enter a city.";
         char prompt4[26] = "Enter a province.";
         char prompt5[26] = "Enter a post code.";
         char prompt6[26] = "Enter a country.";
         char prompt7[26] = "Enter a date of birth.";
         char prompt8[26] = "Enter a phone number.";
         char prompt9[26] = "Enter an email address.";
    
         entry.name = get_input (prompt1, 50);
         entry.add.street = get_input (prompt2, 50);
         entry.add.city = get_input (prompt3, 50);
         entry.add.state = get_input (prompt4, 50);
         entry.add.post = get_input (prompt5, 50);
         entry.add.country = get_input (prompt6, 50);
         entry.birth = get_input (prompt7, 50);
         entry.phone = get_input (prompt8, 50);
         entry.email = get_input (prompt9, 50);
         
         return (entry);
    }    
    
    char *get_input (char prompt[26], int size)
    {
         char string [50];
         char *pointer;
         pointer = &string;
         char junk = 0;
         int length;
         
                    do{
                    printf ("\n%s\n\n>", prompt);
                    fgets(string, sizeof(string), stdin);   
                        if ( strchr(string, '\n') == NULL ){         /* if overflow */
                        printf ("\nYour entry is too long, please try again.\a");
                        while((junk = getchar()) != '\n' && junk != EOF);
                        string[0] = '\0';
                        }
                    } while (string[0] == '\0' || string[0] == '\n');
         length = strlen (string);             
         if (string[length - 1] == '\n'){
             string[length - 1] == '\0';}                            /* replace \n  */
         return *pointer;
    }
    Last edited by SiliconHobo; 12-12-2007 at 07:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM