本文整理汇总了C++中read_integer函数的典型用法代码示例。如果您正苦于以下问题:C++ read_integer函数的具体用法?C++ read_integer怎么用?C++ read_integer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_integer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// Read in the number of cases
FILE *fp = fopen("bigint.in", "r");
FILE *fo = fopen("bigint.out", "w");
int numCases, i;
fscanf(fp, "%d", &numCases);
int operation;
char operand1[200], operand2[200];
for (i = 0; i < numCases; i++) {
fscanf(fp, "%d %s %s", &operation, operand1, operand2);
// Create the big integer structures
struct integer *bigInt1 = read_integer(operand1);
struct integer *bigInt2 = read_integer(operand2);
// Add or subtract the big integers
struct integer *result;
if (operation == 1) {
// Print each big integer operand and the operation to the file
print(fo, bigInt1);
operation == 1 ? fprintf(fo, " + ") : fprintf(fo, " - ");
print(fo, bigInt2);
fprintf(fo, " = ");
result = add(bigInt1, bigInt2);
}
else {
// We want to subtract bigger - smaller
int comparison = compare(bigInt1, bigInt2);
struct integer *bigger = comparison >= 0 ? bigInt1 : bigInt2;
struct integer *smaller = comparison >= 0 ? bigInt2 : bigInt1;
// Print each big integer operand and the operation to the file
print(fo, bigger);
operation == 1 ? fprintf(fo, " + ") : fprintf(fo, " - ");
print(fo, smaller);
fprintf(fo, " = ");
result = subtract(bigger, smaller);
}
// Print the result
print(fo, result);
fprintf(fo, "\n");
// Free the digits and then the structure
free(bigInt1->digits);
free(bigInt1);
free(bigInt2->digits);
free(bigInt2);
free(result->digits);
free(result);
}
fclose(fp);
fclose(fo);
}
示例2: read_rgb
//write the rgb value in gdkcolor
unsigned char read_rgb(GdkColor *pGdkColor, FILE * file)
{
int iColor;
if ( !read_integer(&iColor, file) )
{
SB_INKERRPRINTF("failed\n");
return 0;
}
pGdkColor->red=(guint16)iColor;
if ( !read_integer(&iColor, file) )
{
SB_INKERRPRINTF("failed\n");
return 0;
}
pGdkColor->green=(guint16)iColor;
if ( !read_integer(&iColor, file) )
{
SB_INKERRPRINTF("failed\n");
return 0;
}
pGdkColor->blue=(guint16)iColor;
SB_INKPRINTF("rgb(%d,%d,%d) \n",
pGdkColor->red, pGdkColor->green,pGdkColor->blue);
return 1;
}
示例3: read_polygon_xyz
void read_polygon_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_rings = read_integer();
if (num_rings > 0)
{
std::unique_ptr<geometry_type> poly(new geometry_type(geometry_type::types::Polygon));
for (int i = 0; i < num_rings; ++i)
{
int num_points = read_integer();
if (num_points > 0)
{
CoordinateArray ar(num_points);
read_coords_xyz(ar);
poly->move_to(ar[0].x, ar[0].y);
for (int j = 1; j < num_points; ++j)
{
poly->line_to(ar[j].x, ar[j].y);
}
poly->close_path();
}
}
if (poly->size() > 2) // ignore if polygon has less than 3 vertices
paths.push_back(poly.release());
}
}
示例4: log_error
bool G_SoldierMakeMgr::init() {
auto tab_info = the_app->script()->read_table("the_soldier_make_info");
if (tab_info->is_nil()) {
return false;
}
G_SoldierMakeInfo *info = nullptr;
for (unsigned i = 1; ; ++i) {
auto tab_item = tab_info->read_table(i);
if (tab_item->is_nil()) {
break;
}
int item_id = tab_item->read_integer("itemid", -1);
if (item_id < 0) {
if (!info) {
continue;
}
}
else {
const G_ItemInfo *item_info = G_ItemMgr::instance()->get_info(item_id);
if (!item_info) {
log_error("unknown item id '%d'.", item_id);
return false;
}
info = probe_info(item_id);
if (info->_use_item) {
log_error("dup item id '%d'.", item_id);
return false;
}
info->_use_item = item_info;
info->_use_count = tab_item->read_integer("itemnumber", 0);
if (!info->_use_count) {
log_error("bad use item count.");
return false;
}
}
int soldier_id = tab_item->read_integer("heroid", -1);
if (soldier_id < 0) {
continue;
}
const G_SoldierInfo *soldier_info = G_SoldierMgr::instance()->get_info(soldier_id);
if (!soldier_info) {
log_error("unknown soldier id '%d'.", soldier_id);
return false;
}
info->_soldiers.push_back(soldier_info);
}
return true;
}
示例5: lock
void
GBitmap::init(ByteStream &ref, int aborder)
{
GMonitorLock lock(monitor());
// Get magic number
char magic[2];
magic[0] = magic[1] = 0;
ref.readall((void*)magic, sizeof(magic));
char lookahead = '\n';
int acolumns = read_integer(lookahead, ref);
int arows = read_integer(lookahead, ref);
init(arows, acolumns, aborder);
// go reading file
if (magic[0]=='P')
{
switch(magic[1])
{
case '1':
grays = 2;
read_pbm_text(ref);
return;
case '2':
grays = 1 + read_integer(lookahead, ref);
if (grays > 256)
G_THROW("Cannot read PGM with depth greater than 8 bits.");
read_pgm_text(ref);
return;
case '4':
grays = 2;
read_pbm_raw(ref);
return;
case '5':
grays = 1 + read_integer(lookahead, ref);
if (grays > 256)
grays = 256;
read_pgm_raw(ref);
return;
}
}
else if (magic[0]=='R')
{
switch(magic[1])
{
case '4':
grays = 2;
read_rle_raw(ref);
return;
}
}
G_THROW( ERR_MSG("GBitmap.bad_format") );
}
示例6: assert
void Book::read_entry(BookEntry& entry, int n) const {
assert(n >= 0 && n < bookSize);
assert(bookFile != NULL);
if(fseek(bookFile, n*16, SEEK_SET) == -1) {
std::cerr << "Failed to read book entry at index " << n << std::endl;
exit(EXIT_FAILURE);
}
entry.key = read_integer(bookFile, 8);
entry.move = read_integer(bookFile, 2);
entry.count = read_integer(bookFile, 2);
entry.n = read_integer(bookFile, 2);
entry.sum = read_integer(bookFile, 2);
}
示例7: network_read_mask
static ssize_t network_read_mask(int fd, uint32_t *mask, size_t words)
{
long read_len;
ssize_t ret;
ret = read_integer(fd, &read_len);
if (ret < 0)
return ret;
if (read_len > 0 && mask) {
size_t i;
char buf[9];
buf[8] = '\0';
DEBUG("Reading mask\n");
for (i = words; i > 0; i--) {
ret = read_all(buf, 8, fd);
if (ret < 0)
return ret;
sscanf(buf, "%08x", &mask[i - 1]);
DEBUG("mask[%i] = 0x%x\n", i - 1, mask[i - 1]);
}
}
if (read_len > 0) {
char c;
ssize_t nb = read_all(&c, 1, fd);
if (nb > 0 && c != '\n')
read_len = -EIO;
}
return (ssize_t) read_len;
}
示例8: main
int main(int argc, char **argv)
{
CLIENT client_struct, *c;
FLICK_SERVER_LOCATION s;
int sel, done;
c = &client_struct;
if (argc != 2) {
fprintf(stderr, "Usage: %s <host>\n", argv[0]);
exit(1);
}
s.server_name = argv[1];
s.prog_num = netphone;
s.vers_num = firstphone;
create_client(c, s);
done = 0;
while (!done) {
read_integer(("\n(1) Add an entry (2) Remove an entry "
"(3) Find a phone number (4) Exit: "),
&sel);
switch(sel) {
case 1: add_entry(c); break;
case 2: remove_entry(c); break;
case 3: find_entry(c); break;
case 4: done = 1; break;
default: printf("Please enter 1, 2, 3, or 4.\n");
}
}
return 0;
}
示例9: exec_command
static long exec_command(const char *cmd, int fd)
{
long resp;
ssize_t ret = write_command(cmd, fd);
if (ret < 0)
return (long) ret;
DEBUG("Reading response\n");
ret = read_integer(fd, &resp);
if (ret < 0) {
char buf[1024];
iio_strerror(-ret, buf, sizeof(buf));
ERROR("Unable to read response: %s\n", buf);
return (long) ret;
}
#if LOG_LEVEL >= DEBUG_L
if (resp < 0) {
char buf[1024];
iio_strerror(-resp, buf, sizeof(buf));
DEBUG("Server returned an error: %s\n", buf);
}
#endif
return resp;
}
示例10: read
geometry_ptr read()
{
geometry_ptr geom;
int type=read_integer();
switch (type)
{
case wkbPoint:
geom = read_point();
break;
case wkbLineString:
geom = read_linestring();
break;
case wkbPolygon:
geom = read_polygon();
break;
case wkbMultiPoint:
geom = read_multipoint();
break;
case wkbMultiLineString:
geom = read_multilinestring();
break;
case wkbMultiPolygon:
geom=read_multipolygon();
break;
case wkbGeometryCollection:
break;
default:
break;
}
return geom;
}
示例11: read_error_code
static ssize_t read_error_code(int fd)
{
/*
* The server returns two integer codes.
* The first one is returned right after the WRITEBUF command is issued,
* and corresponds to the error code returned when the server attempted
* to open the device.
* If zero, a second error code is returned, that corresponds (if positive)
* to the number of bytes written.
*
* To speed up things, we delay error reporting. We just send out the
* data without reading the error code that the server gives us, because
* the answer will take too much time. If an error occured, it will be
* reported by the next call to iio_buffer_push().
*/
unsigned int i;
long resp = 0;
for (i = 0; i < 2; i++) {
ssize_t ret = read_integer(fd, &resp);
if (ret < 0)
return ret;
if (resp < 0)
return (ssize_t) resp;
}
return (ssize_t) resp;
}
示例12: read_entry
static void read_entry(entry_t * entry, int n) {
ASSERT(entry!=NULL);
ASSERT(n>=0&&n<BookSize);
ASSERT(BookFile!=NULL);
if (fseek(BookFile,n*16,SEEK_SET) == -1) {
my_fatal("read_entry(): fseek(): %s\n",strerror(errno));
}
entry->key = read_integer(BookFile,8);
entry->move = read_integer(BookFile,2);
entry->count = read_integer(BookFile,2);
entry->n = read_integer(BookFile,2);
entry->sum = read_integer(BookFile,2);
}
示例13: read_multilinestring_xyz
void read_multilinestring_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_lines = read_integer();
for (int i = 0; i < num_lines; ++i)
{
pos_ += 5;
read_linestring_xyz(paths);
}
}
示例14: read_multipolygon_xyz
void read_multipolygon_xyz(boost::ptr_vector<geometry_type> & paths)
{
int num_polys = read_integer();
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
read_polygon_xyz(paths);
}
}
示例15: read_collection
void read_collection(boost::ptr_vector<geometry_type> & paths)
{
int num_geometries = read_integer();
for (int i = 0; i < num_geometries; ++i)
{
pos_ += 1; // skip byte order
read(paths);
}
}