Find the answer to your Linux question:
Results 1 to 5 of 5
Hi I am new to C programming I am given a small task of doing error handling of a program.To write a small function called xit() for this reason... The ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Location
    Bochum,Germany
    Posts
    5

    Error Hnadling in C

    Hi
    I am new to C programming
    I am given a small task of doing error handling of a program.To write a small function called xit() for this reason...
    The program looks as follows.

    void xit(errmsg, icode)
    char *errmsg;
    int *icode,errCode;

    { printf(" Error occured reason - %s and Reason code %d " ,errmsg,icode);

    exit(1);
    }
    The arguments errmsg, icode are taken from some other functions where the error message and code needs to be printed.
    I need to print the Error message and the code on the terminal.

    Can someone guide me how to proceed further

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Is this for a class, or a job? In any case, there are several errors here, including the signature of the function declaration. You are using old style C function declaration, as opposed to standard C which would have the type information along with the variable names inside the (). You have an extra argument declared, but not in the (). You have declared a pointer to integer variable, but are passing it as an integer to the printf() function. I won't get into more specifics here since as you say, you are very new (obviously) to C programming. Spend some $$ and purchase K&R. It will prove to be one of your better investments.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    May 2009
    Location
    Bochum,Germany
    Posts
    5
    Its part of my studies ...being Mechanical Engg..has not done much of programming... ,i am learning C now..so i just thought i ask the experts who can guide me in this...

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by shiva2285 View Post
    Its part of my studies ...being Mechanical Engg..has not done much of programming... ,i am learning C now..so i just thought i ask the experts who can guide me in this...
    Fair enough. However, though we can guide you, we cannot do your school work for you. I hope my suggestions were clear enough to get you going in the right direction. FYI, K&R is the Kernighan and Ritchie book "The C Programming Language". The current edition covers the ANSI standard version of the language. The "old style" that I mentioned is commonly known as the K&R style, because that's how it was done when K&R first invented the C language. I have both editions on my shelf because I started C programming long before the ANSI standard was out, back in the very early 1980's with the first C compiler available for micro-processors. Before that, you needed a PDP-8 at least to get a C compiler from AT&T.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    May 2009
    Location
    Bochum,Germany
    Posts
    5
    Hi
    Thanks for your replies. I was able to do it myself somehow. I changed the signature of function declaration in the header files (which was actually typed wrong) and i could make it work now.
    PS: I have asked experts advise to correct me where i am wrong so that i can work from there on and i would not want someone to do all my work for me anyways.

    Thanks for time and advise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...