Thread: Syntax error before a structure

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    27

    Syntax error before a structure

    This is a file name valid.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #include "valid.h"
    #include "structure.h"
    
    int checkCode(char* codeString,DATA_T* pResult)
    {
        int status = 1;
        int i = 0;
        char countryCode[3];
        char passportNum[13];
    
        if((strlen(codeString)<11)||(strlen(codeString)>15))
            {
            status = ERR_BADFORM;
            }
        else if (codeString[2] != '-')
            {
            status = ERR_BADFORM;
            }
        else
            {
            /* check that the first two are alphabets */
            for (i = 0; (i < 2) && (status > 0); i++)
                {
                if (!isalpha(codeString[i]))
                    {
                    status = ERR_CODE;
                    }
                if ((codeString[i]<=97)||(codeString[i]>=122))
                    {
                    codeString[i] = codeString[i] - 32;
                    }
                }
            /* check that all other chars are digits */
            for (i = 2; (i < 13) && (status > 0); i++)
                {
                if (!isdigit(codeString[i]))
                    {
                    status = ERR_NUM;
                    }
                }
                /* If the status is still positive, then we know the format is good */
                if (status > 0)
                    {
                    sscanf(codeString,"%s-%s",countryCode,passportNum);
                    strcpy(pResult->passportID,countryCode);
                    strcat(pResult->passportID,"-");
                    strcat(pResult->passportID,passportNum);
                    }
            }
    
        return status;
    }
    This is a file name valid.h
    Code:
    #define ERR_BADFORM     -10
    #define ERR_CODE        -11
    #define ERR_NUM         -12
    
    int checkCode(char* codeString,DATA_T * pResult);
    This is a file name structure.h
    Code:
    typedef struct
    {
        char passportID[16];        /* Passport ID of the user */
        char firstName[30];         /* First name of the user */
        char lastName[30];          /* Last name of the user */
        char expireDate[10];        /* Expiration date of the passport */
        char entryDate[10];         /* Date of last entry into Thailand */
        char exitDate[10];          /* Date of last exit from Thailand */
        char visaType[30];          /* Type of visa */
    } DATA_T;
    I've been getting error in the valid.h saying that
    the red line: error: syntax error before DATA_T
    Can anyone help me with this?

    Thank you

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    structure.h follows valid.h in your include list, so the compiler knows nothing about DATA_T in valid.h.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    27
    Thanks a lot ^^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple syntax errors
    By Devolution in forum C Programming
    Replies: 1
    Last Post: 03-25-2009, 10:37 PM
  2. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  3. passing structure arrays to functions?
    By bem82 in forum C Programming
    Replies: 3
    Last Post: 10-30-2006, 06:17 AM
  4. What's wrong with this code??
    By Xanth in forum C Programming
    Replies: 11
    Last Post: 12-23-2004, 02:41 PM
  5. Some structure and Syntax Help Please!
    By jessweetd in forum C Programming
    Replies: 4
    Last Post: 09-30-2004, 11:13 PM