Thread: Error when I try to compile

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    12

    Error when I try to compile

    When I try to compile, I get the error:

    error: expected expression before 'char'

    Here is the part it talks about:

    Code:
    int get_names(int students, char names[students][20])
    {
            int i;
            for (i = 0; i < students; ++i)
            {
                    printf("Enter name for Student %d: ", i);
                    scanf("%s", names[i]);
            }
            return char names[students];
    }
    Why is this not working?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > return char names[students];
    You've got a type here, and there shouldn't be.

    Secondly, names[students] is both a char pointer, and a buffer overflow.
    Yet the function says it is returning an int.
    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. Compile error? Logic error? Syntax Error? Please help
    By Khody Afkhami in forum C Programming
    Replies: 4
    Last Post: 10-11-2014, 01:36 AM
  2. Replies: 15
    Last Post: 11-28-2011, 11:48 AM
  3. compile time error or runtime error?
    By George2 in forum C# Programming
    Replies: 3
    Last Post: 05-07-2008, 07:08 AM
  4. 0 compile error but 2 build error. need help please!
    By jibbles in forum C Programming
    Replies: 5
    Last Post: 08-30-2004, 04:30 PM
  5. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 06:00 AM