Thread: Problem with simple C programming

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

    Problem with simple C programming

    Hi, I am having programming issues with C. I have not used C in quite a long time, and I am trying to refresh my practice of C for I need to use it for work. The program that I am having compiling issues with makes use of derived data type and structure. It is very simple, and taken directly from a textbook (see code at the end of post), however, I am getting the following compiling errors:

    test.c:4: error: expected ‘)’ before ‘.’ token
    test.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
    test.c:6: error: expected declaration specifiers or ‘...’ before string constant
    test.c:6: error: expected declaration specifiers or ‘...’ before ‘student_1’
    test.c:6: error: expected declaration specifiers or ‘...’ before ‘student_1’
    test.c:6: warning: data definition has no type or storage class
    test.c:6: error: conflicting types for ‘printf’
    test.c:6: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration


    I use gcc compiler.
    Any idea what is wrong with my code??
    Thanks for any help you can provide.

    Sincerely,

    Yann


    CODE:
    (header file)
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct {
    	char name[20];
    	int age;
    	int course_code;
    	int course_year;
    	long int student_id;
    } Student;
    (main file)
    Code:
    #include "header.h"
    
    Student student_1;
    strcpy(student_1.name, "Smith, Bert");
    student_1.age = 17;
    printf("student name %s, age %d ", student_1.name, student_1.age);

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perhaps you'd like to put your actual code inside a function (say main() or some such).

    --
    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.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    2
    That was easy!
    Thanks for the help.

    YAV

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM