Thread: Required Parameter Missing help

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    10

    Required Parameter Missing help

    Hi, i'm new to the forum and C programming and I was wondering if someone could help me with the message "Required parameter missing" that I get when I run my program in DOS.

    I'm currently working my way through the C programming language 2nd edition by Brian W. Kernighan and i've got the chapter "Character Input and Output" with no problems at all.

    I've used the following code;

    Code:
    #include <stdio.h>
    
    main()
    {
    int c;
    
    c=getchar();
    while (c != EOF) {
    putchar(c);
    c = getchar();
    }
    }
    I have also tried the following code;

    Code:
    #include <stdio.h>
    
    main()
    {
    int c;
    while ((c = getchar())) !=EOF)
    putchar(c);
    }
    I can build the code with no errors or warnings, but when I load it in DOS I get the Required Parameter Missing message.

    Please can anyone help, it would be greatly appreciated.

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    main() isn't really legal...I assume the compiler fixed that for you though. That and the lack of a return statement. It really should be:
    Code:
    int main(void)
    {
    ...
    
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    10
    I've tried what you've told me but im still getting the sane message

    Cheers for the quick reply!

  4. #4
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Are you using the 1st or 2nd code? I just noticed that the 2nd code has too many parentheses:

    ((c = getchar())) !=EOF) should be ((c = getchar()) != EOF)

    And should not have compiled.

    Other than that there's nothing wrong...

  5. #5
    Registered User R.Hermans's Avatar
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by Epy View Post
    Other than that there's nothing wrong...
    Should the variable "C" not get a value assigned to it sins it is declared inside a function?

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    How are you running this in DOS? Are you submitting it from a Windows GUI IDE? Have you tried running it from a DOS command prompt independent from the IDE? Perhaps it is your IDE that is complaining when you launch it and not the compiler.

  7. #7
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by R.Hermans View Post
    Should the variable "C" not get a value assigned to it sins it is declared inside a function?
    Most variables are supposed to be declared in main()...you're really supposed to avoid using globals (variables declared outside of a function) whenever possible.

  8. #8
    Registered User R.Hermans's Avatar
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by Epy View Post
    Most variables are supposed to be declared in main()...you're really supposed to avoid using globals (variables declared outside of a function) whenever possible.
    As far as I knew a variable that is declared outside of a function is by default set to "0" when it is an integer.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Epy
    main() isn't really legal
    The lack of a return type may or may not be legal depending on the edition of the C standard, but the empty parentheses certainly is legal here.

    Quote Originally Posted by Epy
    That and the lack of a return statement.
    This is legal with defined behaviour (0 will be returned) with respect to the 1999 edition of the C standard, for the main function only.

    Quote Originally Posted by R.Hermans
    As far as I knew a variable that is declared outside of a function is by default set to "0" when it is an integer.
    Yes, but that is because the rule is that objects with static storage duration are zero initialised automatically. Variables declared in the local scope of a function, unless they are declared static, do not have static storage duration. But I do not see how this is relevant to your program.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User R.Hermans's Avatar
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by laserlight View Post
    Yes, but that is because the rule is that objects with static storage duration are zero initialised automatically. Variables declared in the local scope of a function, unless they are declared static, do not have static storage duration. But I do not see how this is relevant to your program.
    It is not my program. I asked the question because I read that the topic starter did not assigned a value to "C".

  11. #11
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    laserlight, so knowledgeable. I figured it might be legal in one of the later standards, though I don't really know why in the hell they did this other than to cause problems. It's not like putting in a return type or a return statement is time-consuming.

  12. #12
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I read that the topic starter did not assigned a value to "C".
    I see no point in assigning a value before making this call:

    Code:
    c=getchar();

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by R.Hermans
    It is not my program. I asked the question because I read that the topic starter did not assigned a value to "C".
    hmm... unfortunately, I do not read this in any of the posts before your post #5, so it does not make sense to me.

    Quote Originally Posted by Epy
    I figured it might be legal in one of the later standards, though I don't really know why in the hell they did this other than to cause problems. It's not like putting in a return type or a return statement is time-consuming.
    I do not think that it is legal to omit both the return type and the return statement since the 1999 edition of the C standard requires explicit return types, but the previous version requires return statements (otherwise there is undefined behaviour, or maybe the return value is implementation defined).

    As for why: someone here had the theory that the main function returning 0 implicitly is an attempt to compromise with the void main crowd.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User R.Hermans's Avatar
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by laserlight View Post
    hmm... unfortunately, I do not read this in any of the posts before your post #5, so it does not make sense to me.
    Maybe a misunderstanding here. I saw the following code in the first post of this topic:
    Code:
    #include <stdio.h>
    
    main()
    {
    int c;
    while ((c = getchar())) !=EOF)
    putchar(c);
    }
    I am currently learning C myself from the video course VTC offers. It teaches coding according to the C99 standard and it mentioned that you should assign a value to every variable when declaring it inside a function. I am aware that it is not a must but according to the instructor in that video it is good practice.

  15. #15
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Code:
    while ((c = getchar()))
    R.Hermans - do not confuse this with a test for equality. What this while loop does is assign the result of getchar to c, and then as long as c is not a null value, the loop continues.

    Think of it this way: y = x = 3. 3 is assigned to x, and then that same result is assigned back to y. So placing an assignment inside a loop is like placing the end result of that assignment in the test - it's just more compact.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. Consequence of const-ifying a function parameter
    By hzmonte in forum C Programming
    Replies: 3
    Last Post: 08-24-2006, 01:28 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  5. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM