本文整理汇总了C++中readint函数的典型用法代码示例。如果您正苦于以下问题:C++ readint函数的具体用法?C++ readint怎么用?C++ readint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: msglist
int msglist (void)
{
int x;
if (server) {
x = writemsg (MSGLIST);
if (x == SCMOK) x = Tprocess (listT,listone);
if (x == SCMOK) x = writestring ((char *)NULL);
if (x == SCMOK) x = writeint ((int)scantime);
if (x == SCMOK) x = writemend ();
} else {
char *name;
int mode,flags,mtime;
TREE *t;
x = readmsg (MSGLIST);
if (x == SCMOK) x = readstring (&name);
while (x == SCMOK) {
if (name == NULL) break;
x = readint (&mode);
if (x == SCMOK) x = readint (&flags);
if (x == SCMOK) x = readint (&mtime);
if (x != SCMOK) break;
t = Tinsert (&listT,name,TRUE);
free (name);
t->Tmode = mode;
t->Tflags = flags;
t->Tmtime = mtime;
x = readstring (&name);
}
if (x == SCMOK) x = readint ((int *)&scantime);
if (x == SCMOK) x = readmend ();
}
return (x);
}
示例2: handle_request
void handle_request(void) {
void *allocs[100] = {0};
uint32_t alloc_idx;
sendstr(" **** WELCOME TO THE HEAP SIMULATOR 2001! ****\n\n");
while (1) {
sendstr("What would you like to do?\n");
sendstr(" 1) Allocate memory\n");
sendstr(" 2) Free memory\n");
sendstr(" 3) Read some data\n");
sendstr(" 4) Exit\n\n");
int cmd = readint();
uint16_t id;
switch (cmd) {
case 1:
for (alloc_idx = 0; alloc_idx < sizeof(allocs) && allocs[alloc_idx] != NULL; ++alloc_idx) ;
if (alloc_idx >= sizeof(allocs)) {
sendstr("Run out of space, free something first!\n");
} else {
sendstr("Ok, how much memory do you want (in bytes)?\n");
uint16_t bytes = readint();
allocs[alloc_idx] = (void *)alloc(bytes);
sendstr(tprintf("Allocated with ID = %d\n", alloc_idx));
}
dump_heap();
break;
case 2:
sendstr("Please enter the ID of the alloc to free\n");
id = readint();
if (id < sizeof(allocs) && allocs[id] != NULL) {
dealloc(allocs[id]);
allocs[id] = NULL;
} else {
sendstr("Alloc not found\n");
}
dump_heap();
break;
case 3:
sendstr("Please enter the ID of the alloc where to read data\n");
id = readint();
if (id < sizeof(allocs) && allocs[id] != NULL) {
sendstr("Ready! Send the data\n");
recvline(client_fd, allocs[id], 0x100);
} else {
sendstr("Alloc not found\n");
}
dump_heap();
break;
case 4:
say_bye();
exit(0);
break;
default:
sendstr("What!?\n");
};
}
}
示例3: main
int main() {
for (; scanf("%d%d",&n,&m) != EOF;) {
totg = n;
tn = (n*3)/4;
for (i = 0; i <= n; i++) g[i].next = -1;
for (i = 1; i <= n; i++) addedge(0,i,-1);
for (i = 1; i <= m; i++) {
x = readint();
y = readint();
z = readint();
if (x == 1) {
addedge(y,z,0);
addedge(z,y,0);
}
else if (x == 2)addedge(y,z,-1);
else if (x == 3)addedge(z,y,0);
else if (x == 4)addedge(z,y,-1);
else addedge(y,z,0);
}
hasres = SPFA();
if (hasres == 1) {
res = 0;
for (i = 1; i <= n; i++)res += (long long)(-d[i]);
printf("%lld\n",res);
}
else printf("-1\n");
}
}
示例4: comment_add
void comment_add(char **comments, int* length, char *tag, char *val)
{
char* p=*comments;
int vendor_length=readint(p, 8);
int user_comment_list_length=readint(p, 8+4+vendor_length);
int tag_len=(tag?strlen(tag)+1:0);
int val_len=strlen(val);
int len=(*length)+4+tag_len+val_len;
p=(char*)realloc(p, len);
if(p==NULL){
fprintf(stderr, "realloc failed in comment_add()\n");
exit(1);
}
writeint(p, *length, tag_len+val_len); /* length of comment */
if(tag){
memcpy(p+*length+4, tag, tag_len); /* comment tag */
(p+*length+4)[tag_len-1] = '='; /* separator */
}
memcpy(p+*length+4+tag_len, val, val_len); /* comment */
writeint(p, 8+4+vendor_length, user_comment_list_length+1);
*comments=p;
*length=len;
}
示例5: main
/** @brief Programa principal para la practica de PRO2: 'Red ferroviaria'. */
int main() {
// Leer cuantas cocheras
int M = readint();
// Inicializar la red, las cocheras y los trenes
Red red;
red.leer_red();
Cjt_Cocheras cocheras(M);
cocheras.leer_cocheras();
Cjt_Trenes trenes;
trenes.leer_trenes();
// Procesar las opciones
int opcion = readint();
while (opcion != -6) {
if (opcion == -1) cocheras.almacenamiento_nocturno(red, trenes);
else if (opcion == -2) cocheras.formacion_matinal(trenes);
else if (opcion == -3) trenes.leer_tren();
else if (opcion == -4) cocheras.leer_cocheras();
else if (opcion == -5) cocheras.escribir_cocheras();
opcion = readint();
}
return 0;
}
示例6: readint
void Servidor::actualizar_pelicula(){
int x;
x = readint();
addPeliculas(x);
x = readint();
deletePeliculas(x);
}
示例7: main
int main(void) {
int c, lim, s, t;
int *n, *p;
for(readint(t); t--; ) {
readint(s);
readint(c);
for(int i = 0; i < s; ++i) readint(d[0][i]);
for(lim = s; lim--; ) {
bool change = false;
n = d[s - lim];
p = d[s - lim - 1];
for(int i = 0; i < lim; ++i) {
n[i] = p[i + 1] - p[i];
change |= i && n[i] != n[i - 1];
}
if(!change) {
for(int i = lim; i < lim + c; ++i) n[i] = n[0];
break;
}
}
while(lim++ < s) {
n = d[s - lim];
p = d[s - lim + 1] ;
for(int i = lim; i < lim + c; ++i) n[i] = n[i - 1] + p[i - 1];
}
if(s > 1) for(int i = s; i < s + c; ++i) buffer(n[i], i==s+c-1?10:32);
else for(int i = 0; i < c; ++i) buffer(d[0][0], i==c-1?10:32);
}
flush_buffer();
return 0;
}
示例8: readint
/**
* Constructor
* @param ss substream to read from
*/
hpiutil::sqshstream::sqshstream(substream &ss)
{
valid = false;
stream = &ss;
boost::uint32_t magic = readint();
if (magic != SQSH_MAGIC) {
std::cerr << "Invalid SQSH header signature: 0x" << std::hex << magic << std::endl;
return;
}
boost::uint8_t unknown = stream->read();
compress = stream->read();
encrypt = stream->read();
compressedsize = readint();
fullsize = readint();
checksum = readint();
boost::uint32_t newcheck = stream->checksum(SQSH_HEADER);
if (checksum && (newcheck != checksum)) {
std::cerr << "Chunk checksum " << std::hex << newcheck << " does not match stored checksum " << std::hex << checksum << std::endl;
return;
}
if (decompress())
valid = true;
else
free((void*)data);
}
示例9: readint2
static int readint2( const char** source, int* x, int* y )
{
if ( readint( source, x ) != 0 )
{
return -1;
}
return readint( source, y );
}
示例10: print_comments
static void print_comments(char *comments, int length)
{
char *c=comments;
int len, i, nb_fields, err=0;
if (length<(8+4+4))
{
fprintf (stderr, "Invalid/corrupted comments\n");
return;
}
if (strncmp(c, "OpusTags", 8) != 0)
{
fprintf (stderr, "Invalid/corrupted comments\n");
return;
}
c += 8;
fprintf(stderr, "Encoded with ");
len=readint(c, 0);
c+=4;
if (len < 0 || len>(length-16))
{
fprintf (stderr, "Invalid/corrupted comments\n");
return;
}
err&=fwrite(c, 1, len, stderr)!=(unsigned)len;
c+=len;
fprintf (stderr, "\n");
/*The -16 check above makes sure we can read this.*/
nb_fields=readint(c, 0);
c+=4;
length-=16+len;
if (nb_fields < 0 || nb_fields>(length>>2))
{
fprintf (stderr, "Invalid/corrupted comments\n");
return;
}
for (i=0;i<nb_fields;i++)
{
if (length<4)
{
fprintf (stderr, "Invalid/corrupted comments\n");
return;
}
len=readint(c, 0);
c+=4;
length-=4;
if (len < 0 || len>length)
{
fprintf (stderr, "Invalid/corrupted comments\n");
return;
}
err&=fwrite(c, 1, len, stderr)!=(unsigned)len;
c+=len;
length-=len;
fprintf (stderr, "\n");
}
}
示例11: main
int main(void) {
int a, b, t;
readint(&t);
for(int cnum = 0; cnum++ < t; ) {
readint(&a);
readint(&b);
printf("Case %d: %d\n", cnum, (a + b)/gcd(a, b));
}
return 0;
}
示例12: readFArr1D
void readFArr1D(ifstream& stream, FArr1D& v)
{
int Lo1, Hi1;
char s[4];
readint(stream, Lo1);
readint(stream, Hi1);
assert( v.L1() == Lo1 && v.H1() == Hi1 ); // Check lim match.
for(int i=Lo1; i<=Hi1; i++) stream >> v(i);
stream.getline(s, 4);
// stream.ignore(80, '\n');
};
示例13: readint
/** @brief Se leen los trenes para la formacion matinal del canal estandar de entrada.
* \pre cierto
* \post Retorna una lista con los trenes.
*/
list<Tren> Cjt_Cocheras::get_trenes_formacion_matinal(Cjt_Trenes &trenes) const {
list<Tren> trenes_formacion;
int num_trenes = readint();
for (int i = 0; i < num_trenes; i++) {
int id_tren = readint();
Tren tren = trenes.get_tren(id_tren);
trenes_formacion.insert(trenes_formacion.end(), tren);
}
return trenes_formacion;
}
示例14: main
/* }}} end FAST integer input */
int main(void){
int t; readint(t);
for(int cnum = 0, n; cnum++ < t; ){
readint(n);
int cs = 0, ms = 0;
for(int i = 0, p = 0, z; i++ < n; p = z){
readint(z);
int dist = z - p;
if(cs == dist) --cs;
else if(cs < dist) cs = dist > ms ? (ms = dist) - 1 : ++ms;
}
printf("Case %d: %d\n", cnum, ms);
}
return 0;
}
示例15: main_nodisplay
void main_nodisplay() {
float x, y, z = 0;
// main loop
while(1)
{
led1=led2=led3=led4=0;
mnu->SetScreen("Wait for file ...");
while (srv->State() == listen)
Net::poll();
GetFile();
mot->reset();
plan_get_current_position_xyz(&x, &y, &z);
printf("%f %f\n", x,y);
mnu->SetScreen("Laser BUSY...");
char name[32];
srv->getFilename(name);
printf("Now processing file: '%s'\n\r", name);
FILE *in = sd.openfile(name, "r");
while (!feof(in))
{
while (!mot->ready() );
mot->write(readint(in));
}
fclose(in);
removefile(name);
// done
printf("DONE!...\n");
while (!mot->ready() );
mot->moveTo(cfg->xrest, cfg->yrest, cfg->zrest);
}
}