Examine the following!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gasteven
    New Member
    • Nov 2009
    • 2

    Examine the following!!

    #include <stdio.h>
    #include <string.h>
    int main()
    {
    printf("%s\n", strerror(2));
    return 0;
    /*indicates successful termination */
    }/*end main*/

    What is the above demonsrating?

    A, a function takes an error number and creates an error message string
    B,A function takes a string as an argument and returns the number of characters in the string.
    C,A function copies the value of the byte and includes it as an error in the printf.
    D,None above

    I got this question wrong and I like to corrrect myself plz help.
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Originally posted by gasteven
    I got this question wrong and I like to corrrect myself plz help.
    What [wrong] answer did you give before?

    Comment

    • gasteven
      New Member
      • Nov 2009
      • 2

      #3
      I put A and it was wrong! I like to know the right answer.

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        The correct answer still is A). It demonstrates usage of strerror() that "takes an error number and creates an error message string" which you can check in any C reference. ( just google for strerror). No part of this code "returns the number of characters in the string" or "function copies the value of the byte and includes it as an error" ( e.g. because int as a strerror's argument is not a byte)

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          Originally posted by gasteven
          Code:
          #include <stdio.h>
          #include <string.h>
          int main()
          {
              printf("%s\n", strerror(2));
              return 0;          /*indicates successful termination */
          } /*end main*/
          What is the above demonstrating?
          Originally posted by gasteven
          I put A and it was wrong! I like to know the right answer.
          I assume the point of the question is to describe what main does.

          You need to familiarize yourself with standard library function strerror. Your program creates the error message string corresponding to error number 2; and then prints that error message string to stdout.

          Consider answer A: a function takes an error number and creates an error message string. This is pretty close. Your program is hard coded for error number 2. Your program prints the error message string after creating it.

          Consider answer B: a function takes a string as an argument and returns the number of characters in the string. This can't be right because your function doesn't have any arguments.

          Consider answer C: a function copies the value of the byte and includes it as an error in the printf. This can't be right because the error number value ("2") is not present in the printed text.

          Consider answer D: none of the above. This is a possibility. It depends on whether the instructor considers the exceptions noted above for answer A to be significant.

          Comment

          Working...