0

I'm trying to store a string with a first and last name from a string into a struct but I'm getting (warning: passing argument 1 of strcpy makes pointer from integer without a cast), and I'm not sure on where to put strcpy tried putting it in the while loop got the error which makes sense. But not sure on where to place strcpy EDITED

 struct trip

    {
     char first_name;
     char last_name;

    }
    int main(void)
    {
     struct trip travel[12];
    }

    char input_name(struct trip travel[MAXTRIP], int index)
    {
      int name_read, length; 
      int name_bytes = 100;
      char *name, *word;                 

      getchar();
      printf("Please enter name:\n");

      name = (char *)malloc(name_bytes + 1);
      name_read = getline (&name, &name_bytes, stdin);

      word = strtok(name, ",");
      while (word != NULL)
        {
          strcpy(travel[index].first_name, word);
          word = strtok(NULL, ",");

        }


    }
4
  • 2
    What is word? What is name? How have you declared your variables? Are you actually getting that error message? strcpy isn't used anywhere in your program. Commented Mar 26, 2011 at 18:30
  • 5
    Please post your actual code. There is no strcpy shown above and you don't show what most of your variables are. Commented Mar 26, 2011 at 18:30
  • 2
    In your struct you can only hold two characters: one for first name and another for last name. If you want to hold more characters define an array or a pointer to array (char *) and allocate memory dynamically. Commented Mar 26, 2011 at 18:38
  • Like wenuxas says, your struct defines first_name and last_name as single characters. The error is from the character being promoted to integer when passed to strcpy. Commented Mar 26, 2011 at 18:43

1 Answer 1

4

Ignoring the (MANY) errors in your code, you are putting the strcpy() in the right place.

However, you are not calling it with the correct arguments: strcpy() needs 2 arguments.
Basically, both are of type char*; you are passing a char and a char* and that is why the compiler complains (for the compiler the char behaves like an int so it says "strcpy makes pointer from integer").

You need to review your data structure and pass the right char*s to strcpy().

Sign up to request clarification or add additional context in comments.

1 Comment

Yea I was looking over my notes and seems like I'm passing it in wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.