Sponsored Content
Top Forums Programming help with C programming, perror Post 302496167 by hergp on Saturday 12th of February 2011 02:53:49 PM
Old 02-12-2011
You can't. The second part of the message is derived from the current value of the "errno" variable. The strings come from message files or directly from libc and cannot be altered.

If you want a completely customized message, just use fprintf instead:
Code:
fprintf (stderr, "WRONG!!! : WRONG!!!\n");

 

10 More Discussions You Might Find Interesting

1. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies

2. Shell Programming and Scripting

Unix Systems Programming Vs Unix Programming

Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do. It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies

3. Programming

C++ programming

Sorry to ask this question here... where can I find a C++ programming thread? Thanks guys! (7 Replies)
Discussion started by: nadiamihu
7 Replies

4. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

5. Programming

A question about printing error message with perror

Dear all, I use perror in order to print an error message to the standar error. For example if a C program is called without its two necessary command line parameters then : if (argc != 3) { perror("use: ./myProgram <source file> <target file>\n"); return 1; } Now the... (2 Replies)
Discussion started by: dariyoosh
2 Replies

6. Programming

does perror() set errno?

here the program gives a odd result: #include <stdio.h> int main(){ perror("first"); perror("next"); return 0; } result: first: Success next: Illegal seek why? any resonable explanation? i found no information about this in man pages. thanks in advance (2 Replies)
Discussion started by: ebd
2 Replies

7. Programming

C Programming - Hardware Programming

Can someone help me on suggesting some ways to access the memory content in RAM directly from C/C++ source code. Please provide me any book name or any URL so that I can get an exhaustive knowledge over it. If possible please give me some tips on interacting with hardwares directly through... (3 Replies)
Discussion started by: nandumishra
3 Replies

8. UNIX for Dummies Questions & Answers

perror with signals

I have following problem with this code.. First time trough the main loop..... perror gives ....blocked signal:success(all other times gives illlegal seek) Should every time trought the main loop be success?? And the perror otside of main loop...didn't change mask:success That line of code... (2 Replies)
Discussion started by: joker40
2 Replies

9. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

10. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies
explain_fprintf(3)					     Library Functions Manual						explain_fprintf(3)

NAME
explain_fprintf - explain fprintf(3) errors SYNOPSIS
#include <libexplain/fprintf.h> const char *explain_fprintf(FILE *fp, const char *format, ...); const char *explain_errno_fprintf(int errnum, FILE *fp, const char *format, ...); void explain_message_fprintf(char *message, int message_size, FILE *fp, const char *format, ....); void explain_message_errno_fprintf(char *message, int message_size, int errnum, FILE *fp, const char *format, ...); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the fprintf(3) system call. explain_fprintf const char *explain_fprintf(FILE *fp, const char *format, ...); The explain_fprintf function is used to obtain an explanation of an error returned by the fprintf(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. fp The original fp, exactly as passed to the fprintf(3) system call. format The original format, exactly as passed to the fprintf(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = fprintf(fp, format, ...); if (result < 0) { fprintf(stderr, "%s ", explain_fprintf(fp, format, ...)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fprintf_or_die(3) function. explain_errno_fprintf const char *explain_errno_fprintf(int errnum, FILE *fp, const char *format, ...); The explain_errno_fprintf function is used to obtain an explanation of an error returned by the fprintf(3) system call. The least the mes- sage will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fp The original fp, exactly as passed to the fprintf(3) system call. format The original format, exactly as passed to the fprintf(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = fprintf(fp, format, ...); if (result < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_fprintf(err, fp, format, ...)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fprintf_or_die(3) function. explain_message_fprintf void explain_message_fprintf(char *message, int message_size, FILE *fp, const char *format, ...); The explain_message_fprintf function is used to obtain an explanation of an error returned by the fprintf(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. fp The original fp, exactly as passed to the fprintf(3) system call. format The original format, exactly as passed to the fprintf(3) system call. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = fprintf(fp, format, ...); if (result < 0) { char message[3000]; explain_message_fprintf(message, sizeof(message), fp, format, ...); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fprintf_or_die(3) function. explain_message_errno_fprintf void explain_message_errno_fprintf(char *message, int message_size, int errnum, FILE *fp, const char *format, ...); The explain_message_errno_fprintf function is used to obtain an explanation of an error returned by the fprintf(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fp The original fp, exactly as passed to the fprintf(3) system call. format The original format, exactly as passed to the fprintf(3) system call. Example: This function is intended to be used in a fashion similar to the following example: errno = EINVAL; int result = fprintf(fp, format, ...); if (result < 0) { int err = errno; char message[3000]; explain_message_errno_fprintf(message, sizeof(message), err, fp, format, ...); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_fprintf_or_die(3) function. SEE ALSO
fprintf(3) formatted output conversion explain_fprintf_or_die(3) formatted output conversion and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_fprintf(3)
All times are GMT -4. The time now is 07:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy