Sponsored Content
Top Forums Programming Need a simple example of passing FILE pointers Post 302164533 by user_prady on Tuesday 5th of February 2008 06:09:10 AM
Old 02-05-2008
is there any problem if I dont close a file after opening it?

Quote:
Originally Posted by user_prady
Really many many Thanks for the help .

I ll neva forget this..

IS there any problem if I omit the line fclose(fp); if the fp is open .

If yes what ll be the problem..
 

10 More Discussions You Might Find Interesting

1. Programming

Pointers to Arrays

Below is the program i tried to execute...... main() { static int a = {0,1,2,3,4}; static int *p = {a, a+1, a+2, a+3, a+4}; printf (“\n %u %u %d”, p, *p, *(*p) ); } This works, but i wanted to know why both a and *p are declared as "static". If we dont declare a as static... (2 Replies)
Discussion started by: Jayathirtha
2 Replies

2. Programming

Regarding Function and Pointers.

HI, Here is some thing that is puzzling me from a long time. Can some body explain me this with example. The question is :- What is the difference between function pointer and pointer to a function. Where do we actually use the function pointers and pointer to functions. Thanks in... (0 Replies)
Discussion started by: S.Vishwanath
0 Replies

3. Programming

Pointers and array

hi all, let say i have a pointer exit, and this exit will store some value. how can i store the value that the pointer points to into an array and then print them out from the array. thanks in advance (2 Replies)
Discussion started by: dianazheng
2 Replies

4. Programming

pointers

is this a valid c declaration int (*ptr(int *b)); plz explain... (4 Replies)
Discussion started by: areef4u
4 Replies

5. Programming

pointers

Hi I mash with pointers in C. I solve this problem about 5 hours and I don't know how I should continue. void InsertFirst (tList *L, int val) { tElemPtr new; if((new = malloc(sizeof(tElemPtr))) == NULL) Error(); new->data = val; new->ptr = L->frst; L->frst = new;... (2 Replies)
Discussion started by: Milla
2 Replies

6. Programming

Need help with the Pointers in C

I have a special character called ô. When it is declared as a character variable its showing it can be printed. But when it is declared as a character pointer variable its showing it cannot be printed. I am just wondering why its happening like this.. c1 = '@'; c2 = 'ô'; char *fp; fp="XXô"; if... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

7. Programming

Problem With Pointers

Hi guys. What is the difference between these: 1. int *a; 2. int (*a); (2 Replies)
Discussion started by: majid.merkava
2 Replies

8. Homework & Coursework Questions

Passing pointers to struct

Hi, i'm trying to copy a struct into a binary file using the unix instruction write, so i declare and fill the struct "superbloque" in one function "initSB" and then i pass the pointer to another function called bwrite (for block write) which calls write. The problem is that i call the function... (2 Replies)
Discussion started by: ignatius3
2 Replies

9. Programming

Passing Pointers by reference in C++ Problem

Hello All, I am having this issue...where I am actually having hard time understanding the problem: The code is as follows: #include<iostream.h> void fxn(char*** var) { int i =4; *var = (char**)malloc(i*sizeof(char*)); for(int j =0; j<4; j++) { *var = "name"; cout<<*var;... (6 Replies)
Discussion started by: mind@work
6 Replies

10. Programming

Pointer to pointers

Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It. Can someone help? #include <stdio.h> #include <stdlib.h> #include <assert.h> int f1(char **str_); int main(int argc, char **argv) { char *str = NULL; f1(&str); ... (3 Replies)
Discussion started by: pharaoh
3 Replies
varargs(5)							File Formats Manual							varargs(5)

NAME
varargs - handle variable argument list SYNOPSIS
DESCRIPTION
This set of macros enables programmers to write portable procedures that accept variable argument lists. Routines that have variable argu- ment lists (such as but do not use are inherently nonportable, because different machines use different argument-passing conventions (see printf(3S)). is used as the parameter list in a function header. is a declaration for No semicolon should follow is a type defined for the variable used to traverse the list. is called to initialize pvar to the beginning of the list. The type of argN should be the same as the argument to the function just before the variable portion of the argument list. returns the next argument in the list pointed to by type is the type the argument is expected to be. Different types can be mixed, but it is up to the routine to know what type of argument is expected, because it cannot be determined at runtime. is used to clean up. Multiple traversals, each bracketed by are possible. NOTE: The header file is provided for compatibility with pre-ANSI compilers and earlier releases of HP C/HP-UX. It is superceded by which includes all of the macros. EXAMPLE
The following example shows a possible implementation of (see exec(2)): The next example illustrates how a function that receives variable arguments can pass these arguments down to other functions. To accom- plish this, the first routine in this example) which receives the variable argument list must pass the address pointer resulting from a call to on to any subsequent calls that need to access this same variable argument list. All routines that receive this address pointer in this example) need only to use to access the original variable argument list just as if they were the original routine to be passed the variable arguments. In this example, one can imagine that there are a series of other routines (such as a and that also call the function. #include <stdio.h> #include <varargs.h> #include <unistd.h> int error_count; /* VARARGS4 -- for lint */ int log_errors(log_fp, func_name, err_num, msg_fmt, va_alist) FILE *log_fp; char *func_name; int err_num; char *msg_fmt; va_dcl { va_list ap; /* Print error header information */ (void) fprintf(log_fp, " ERROR in process %d ", getpid()); (void) fprintf(log_fp, " function "%s": ", func_name); switch(err_num) { case ILLEGAL_OPTION: (void) fprintf(log_fp, "illegal option "); break; case CANNOT_PARSE: (void) fprintf(log_fp, "cannot parse input file "); break; ... } /* * Get pointer to first variable argument so that we can * pass it on to v_print_log(). We do this so that * v_print_log() can access the variable arguments passed * to this routine. */ va_start(ap); v_print_log(log_fp, msg_fmt, ap); va_end(ap); } /* VARARGS2 -- for lint */ int v_print_log(log_fp, fmt, ap) FILE *log_fp; char *fmt; va_list ap; { /* * If "%Y" is the first two characters in the format string, * a second file pointer has been passed in to print general * message information to. The rest of the format string is * a standard printf(3S) format string. */ if ((*fmt == '%') && (*(fmt + 1) == 'Y')) { FILE *other_fp; fmt += 2; other_fp = (FILE *) va_arg(ap, char *); if (other_fp != (FILE *) NULL) { /* * Print general message information to additional stream. */ (void) vfprintf(other_fp, fmt, ap); (void) fflush(other_fp); } } /* * Now print it to the log file. */ (void) vfprintf(log_fp, fmt, ap); } WARNINGS
It is up to the calling routine to specify how many arguments there are, because it is not always possible to determine this from the stack frame. For example, is passed a zero pointer to signal the end of the list. can determine how many arguments are present by the format. It is non-portable to specify a second argument of or to because arguments seen by the called function are not or C converts and arguments to and converts arguments to before passing them to a function. SEE ALSO
exec(2), vprintf(3S), stdarg(5). STANDARDS CONFORMANCE
varargs(5)
All times are GMT -4. The time now is 11:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy