Thread: Help using strcpy

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    13

    Help using strcpy

    i am trying to copy a string that i got from a file using fscanf into my struct

    Code:
    struct Room {
      char south, north, east, west;
      char id;
      char description[MAX_SIZE_DESC];
      char name[MAX_SIZE_NAME];
    };
    
    int buildRooms(char filename[], struct Room list[])
    {
      char id[2];
      char roomname [20];
      char north[2];
      char east[2];
      char west[2];
      char south[2];
      char sentence [100];
      char space[4];
      FILE *f = fopen(filename, "r");
      if (f == NULL) {
        fprintf(stderr, "Error opening game file %s./n", filename);
        return 42;}              // failure                                                                    
      else{
          fscanf(f,"%s%s%s%s%s%s",id, roomname, north, east, west, south);
          fgets(space, sizeof(space),f);
          fgets(sentence, sizeof(sentence),f);
          struct Room list;
          strcpy(list.id, id);
      }
     fclose(f);
      return 0;                   // success                                                                   
    }
    i am having trouble in the first strcpy it is saying that i am passing the first argument of strcoy makes pointer from integer without a cast

    any suggestions

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-19-2010, 07:42 AM
  2. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  3. Strcpy
    By Godders_2k in forum C Programming
    Replies: 17
    Last Post: 12-12-2007, 12:34 PM
  4. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 05:14 PM
  5. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 11:00 PM