Difference between revisions of "Dbputr()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
(3 intermediate revisions by one user not shown) | |||
Line 11: | Line 11: | ||
<input parameters> | <input parameters> | ||
− | char *dbf; /* .DBF file descriptor */ | + | char *dbf; /* .DBF file descriptor */ |
− | long recno; | + | long recno; /* Record number */ |
− | char *record; /* Address of a buffer where | + | char *record; /* Address of a buffer where the record contents are stored */ |
− | the record contents are stored */ | + | |
<output parameters> | <output parameters> | ||
Line 39: | Line 38: | ||
#include "dbl.h" | #include "dbl.h" | ||
− | char *dbf; /* .DBF file descriptor */ | + | char *dbf; /* .DBF file descriptor */ |
− | char record[100]; | + | char record[100]; /* Record buffer */ |
− | int rc; /* Return code | + | int rc; /* Return code */ |
rc = dbputr(dbf, (long) 56, record); | rc = dbputr(dbf, (long) 56, record); | ||
− | if (rc = = SUCCESS) printf("Record added n"); | + | if (rc == SUCCESS) printf("Record added \n"); |
else { | else { | ||
− | printf("error number %d n", rc); | + | printf("error number %d \n", rc); |
exit (1); | exit (1); | ||
} | } | ||
+ | </code> | ||
+ | |||
The second example adds a record to the end of the .DBF file. The function [[dbsize()]] is used to get the size of the .DBF file (the number of the last record). | The second example adds a record to the end of the .DBF file. The function [[dbsize()]] is used to get the size of the .DBF file (the number of the last record). | ||
Line 55: | Line 56: | ||
#include "dbl.h" | #include "dbl.h" | ||
− | char *dbf; | + | char *dbf; /* .DBF file descriptor */ |
− | char record[100]; /* Rrecord buffer | + | char record[100]; /* Rrecord buffer */ |
− | long recno; /* Record number | + | long recno; /* Record number */ |
− | int rc; | + | int rc; /* Return code */ |
dbsize(dbf, &recno); | dbsize(dbf, &recno); | ||
rc = dbputr(dbf, recno + 1, record); | rc = dbputr(dbf, recno + 1, record); | ||
− | if (rc = = SUCCESS) printf("record added n"); | + | if (rc == SUCCESS) printf("record added \n"); |
else { | else { | ||
− | printf("error number % | + | printf("error number %d\n", rc); |
exit (1); | exit (1); | ||
} | } | ||
+ | </code> | ||
Line 75: | Line 77: | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
− | [[Category:Library]] | + | [[Category:Library]] |
Latest revision as of 14:12, 1 May 2009
PURPOSE
put data record into a .DBF file
SYNOPSIS
#include "dbl.h" int dbputr(dbf, recno, record) <input parameters> char *dbf; /* .DBF file descriptor */ long recno; /* Record number */ char *record; /* Address of a buffer where the record contents are stored */ <output parameters> none
RETURN VALUE
The dbputr() function returns 0 for success, or < 0 if an error occurs. See the section on return code values for a detailed list of return codes.
DESCRIPTION
This function writes the contents of the record supplied in a user defined buffer to a .DBF file. The position of the record within the file is determined by the record number. All the records existing in the file starting from this position (if any) will be shifted down to create a space for the new record. For example, if the record to be written has the number 5, and 8 records have been previously written to the file, the 5th, 6th, 7th and 8th records will become 6th, 7th, 8th and 9th respectively. The new record becomes the 5th record.
EXAMPLE
The first example adds the 56th record whose contents are in the "char record[100]" to the .DBF file whose file descriptor is in "char *dbf".
#include "dbl.h" char *dbf; /* .DBF file descriptor */ char record[100]; /* Record buffer */ int rc; /* Return code */ rc = dbputr(dbf, (long) 56, record); if (rc == SUCCESS) printf("Record added \n"); else { printf("error number %d \n", rc); exit (1); }
The second example adds a record to the end of the .DBF file. The function dbsize() is used to get the size of the .DBF file (the number of the last record).
#include "dbl.h" char *dbf; /* .DBF file descriptor */ char record[100]; /* Rrecord buffer */ long recno; /* Record number */ int rc; /* Return code */ dbsize(dbf, &recno); rc = dbputr(dbf, recno + 1, record); if (rc == SUCCESS) printf("record added \n"); else { printf("error number %d\n", rc); exit (1); }
SEE ALSO
dbappend(), dbfield(), dbflush(), dbgetr(), dbputm(), dbputrk(), dbrecin(), dbsize(), dbupdr()