defining struct variable without using typedef

This is a discussion on defining struct variable without using typedef within the C Programming forums, part of the General Programming Boards category; when i define a new variable called temp i get missing ';' before 'type' why?? Code: #include <stdio.h> #include <string.h> ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    defining struct variable without using typedef

    when i define a new variable called temp
    i get
    missing ';' before 'type'

    why??
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
     
    
     
    struct line {
    	char name[21], address[21], ID[10];
    	int grade;
    	int code;
    };
    
    
     
    int main ()
    {
    FILE* c[2];
     struct line  temp;
    
    c[0]=fopen("c:\\fl1.txt","r");//vote files ,each file represents the votes from a college
    c[1]=fopen("c:\\fl2.txt","r");
    struct line temp;
    
    fclose(c[0]);
    fclose(c[1]);
    
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    Which line generates the error?

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    And I'm not 100% sure but could "line" be a reserved word?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,457
    Why do you declare two variables named temp in the main function?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    FILE* c[2];
     struct line  temp;
    
    c[0]=fopen("c:\\fl1.txt","r");//vote files ,each file represents the votes from a college
    c[1]=fopen("c:\\fl2.txt","r");
    struct line temp;
    Perhaps that one? [No, I didn't spot it, but gcc is very thorough and at least in my case gave good indication of what was wrong].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bladactania View Post
    And I'm not 100% sure but could "line" be a reserved word?
    It is not. See below - Laserlight got there a tad before me.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    Missed that...

    By the way, please learn to properly indent your code. Very hard to read otherwise.

  8. #8
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Quote Originally Posted by laserlight View Post
    Why do you declare two variables named temp in the main function?
    ohh thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  4. "error: incomplete type is not allowed"
    By Fahrenheit in forum C++ Programming
    Replies: 9
    Last Post: 05-10-2005, 09:52 PM
  5. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21