Thread: Expected Identifier Error

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    2

    Question Expected Identifier Error

    I keep getting an "expected identifier" error on this part of my code
    Code:
    struct InventoryData =={0,"",0};

    where I don't believe there is any actual issue. I'm using repl.it to write it. This is the only thing blocking me from running my code.
    Last edited by maxx96; 11-24-2018 at 07:41 AM. Reason: missed code

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    Quote Originally Posted by maxx96 View Post
    I keep getting an "expected identifier" error on this part of my code
    Code:
    struct InventoryData =={0,"",0};

    where I don't believe there is any actual issue. I'm using repl.it to write it. This is the only thing blocking me from running my code.
    Please show us your whole source code, or a small program that demonstrates the error. We cannot answer your question with only the code you have shown.

  3. #3
    Registered User
    Join Date
    Nov 2018
    Posts
    2
    Code:
     void newItem(FILE * fPtr)
    {
      printf("%s", "Enter new item number(1-100): ");
      unsigned int productNum;
      scanf("%d", &productNum);
    
      fseek(fPtr, (productNum - 1) * sizeof(struct InventoryData), SEEK_SET);
    
      struct InventoryData == { 0, "", 0 };
    
      fread(&product, sizeof(struct InventoryData), 1, fPtr);
    
      if (product.productCode != 0) {
        printf("Account #%d already contains information. \n", product.productCode);
      } else {
        printf("%s", "Enter product name and product balance\n?");
        scanf("%15s%d", &product.productName, &product.productBalance);
    
        product.productCode = productNum;
    
        fseek(fPtr, (productNum - 1) * sizeof(struct InventoryData), SEEK_SET);
    
        fwrite(&product, sizeof(struct InventoryData), 1, fPtr);
      }
    }
    [/COLOR]
    [/FONT][/COLOR]
    This isn't all of my code but it's the function that the error is in. Hope this helps.
    Last edited by Salem; 11-24-2018 at 08:28 AM. Reason: Removed crayola

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    I still can't see the details of the struct, that is probably in a .h file, nor can I compile the program to see this and any other warnings or errors.

    PLEASE, PLEASE, make sure you are posting PLAIN TEXT code. I can hardly read the code with all the color, and faded font!

    Can you provide a small program that demonstrates the error, if not the whole program?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You seem to be using == instead of =, in your attempt at structure assignment.
    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. error: expected identifier or '(' before 'else'
    By cabisheka in forum C Programming
    Replies: 4
    Last Post: 04-02-2018, 10:00 AM
  2. Replies: 7
    Last Post: 08-22-2015, 07:44 PM
  3. Replies: 11
    Last Post: 04-14-2013, 11:15 AM
  4. error: expected identifier or β(β before βwhileβ
    By philgrek in forum C Programming
    Replies: 9
    Last Post: 04-19-2011, 01:28 PM
  5. Error: expected identifier or ‘(’ before ‘{’ token
    By jpcanaverde in forum C Programming
    Replies: 66
    Last Post: 06-08-2010, 12:53 PM

Tags for this Thread