当前位置: 首页>>代码示例>>C++>>正文


C++ readi函数代码示例

本文整理汇总了C++中readi函数的典型用法代码示例。如果您正苦于以下问题:C++ readi函数的具体用法?C++ readi怎么用?C++ readi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了readi函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    int arr[20];
    int i, n, ep;

    prints("Enter the number of integers n: ");
    n = readi(&ep);
    prints("You entered n = ");
    printi(n);
    prints("\n");

    prints("Enter n integers: ");
    for(i=0; i<n; i++) arr[i] = readi(&ep);
    sort(arr,n);

    prints("The n integers in ascending order: ");
    for(i=0; i<n; i++)
    {
        printi(arr[i]);
        prints(" ");
    }
    prints("\n");

    return 0;
}
开发者ID:biswajitsc,项目名称:tinyC-compiler,代码行数:25,代码来源:ass6_12CS30009_test5.c

示例2: main

int main(){
  int mat[100][100];
  char *c="\nPlease Enter Dimension of matrixr: ";
  char *d="\nPlease Enter the matrix row-wise: ";
  char *e="\nThe Entered matrix is: ";
  char *f="\nThe Transposed matrix is: ";
  char *sp=" ";
  char *ne="\n";
  prints(c);
  int err,n,i,j,k;
  n = readi(&err);
  int temp;
  prints(d);
  for (i = 0; i < n; ++i)
  {
    for (j = 0; j < n; ++j)
    {
      mat[i][j]=readi(&err);
    }
  }
  prints(e);
  prints(ne);
  for (i = 0; i < n; ++i)
  {
    prints(ne);
    for (j = 0; j < n; ++j)
    {
      printi(mat[i][j]);
      prints(sp);
    }
  }
  prints(f);
  prints(ne);

  for (i = 0; i < n; ++i)
  {
    for (j = i+1; j < n; ++j)
    {
      temp=mat[j][i];
      mat[j][i]=mat[i][j];
      mat[i][j]=temp;
    }
    
  }
  for (i = 0; i < n; ++i)
  {
    prints(ne);
    for (j = 0; j < n; ++j)
    {
      printi(mat[i][j]);
      prints(sp);
    }
  }
  prints(ne);
return 0;
}
开发者ID:ma08,项目名称:tinyc,代码行数:56,代码来源:ass4_12CS30035_test4.c

示例3: main

/* Driver program to test above function */
int main()
{
  int arr[50], n, i, err;
  prints("Longest Increasing Subsequence\n");
  prints("Enter number of elements ( < 50)\n");
  n = readi(&err);
  prints("Enter array elements\n");
  for(i = 0; i < n; i++) arr[i] = readi(&err);
  prints("Length of LIS is "); printi(lis( arr, n ) ); prints("\n");
  return 0;
}
开发者ID:anuraganand,项目名称:TinyC-compiler,代码行数:12,代码来源:ass6_12CS30006_test4.c

示例4: dirlink

// Write a new directory entry (name, inum) into the directory dp.
int
dirlink(struct inode *dp, char *name, uint inum)
{
  int off;
  struct dirent de;
  struct inode *ip;

  // Check that name is not present.
  if((ip = dirlookup(dp, name, 0)) != 0){
    iput(ip);
    return -1;
  }

  // Look for an empty dirent.
  for(off = 0; off < dp->size; off += sizeof(de)){
    if(readi(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
      panic("dirlink read");
    if(de.inum == 0)
      break;
  }

  strncpy(de.name, name, DIRSIZ);
  de.inum = inum;
  if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
    panic("dirlink");
  
  return 0;
}
开发者ID:gaohannk,项目名称:xv6-system,代码行数:29,代码来源:fs.c

示例5: loaduvm

// Load a program segment into pgdir.  addr must be page-aligned
// and the pages from addr to addr+sz must already be mapped.
int
//20160313--
loaduvm(pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
//loaduvm(pde_t *pgdir, char *addr, uint offset, uint sz)
{
//20160313--
  uint i, pa, n;
  pte_t *pte;

  if((uint) addr % PGSIZE != 0)
    panic("loaduvm: addr must be page aligned");
  for(i = 0; i < sz; i += PGSIZE){
    if((pte = walkpgdir(pgdir, addr+i, 0)) == 0)
      panic("loaduvm: address should exist");
//20160313--
    pa = PTE_ADDR(*pte);
//20160313--
    if(sz - i < PGSIZE)
      n = sz - i;
    else
      n = PGSIZE;
//20160313--
    if(readi(ip, p2v(pa), offset+i, n) != n)
      return -1;
  }
  return 0;
}
开发者ID:ismaellc,项目名称:SOTR,代码行数:29,代码来源:vm.c

示例6: loaduvm

// Load a program segment into pgdir.  addr must be page-aligned
// and the pages from addr to addr+sz must already be mapped.
int loaduvm (pgd_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
{
    uint i, pa, n;
    pte_t *pte;

    if ((uint64) addr % PTE_SZ != 0) {
        panic("loaduvm: addr must be page aligned");
    }

    for (i = 0; i < sz; i += PTE_SZ) {
        if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
            panic("loaduvm: address should exist");
        }

        pa = PTE_ADDR(*pte);

        if (sz - i < PTE_SZ) {
            n = sz - i;
        } else {
            n = PTE_SZ;
        }

        if (readi(ip, p2v(pa), offset + i, n) != n) {
            return -1;
        }
    }

    return 0;
}
开发者ID:finallyjustice,项目名称:xv6-OS-for-arm-v8,代码行数:31,代码来源:vm.c

示例7: main

int main()
{
    int a,b;
    int *e;
    
    prints("***********************Some random outputs!!*************************\n");
    
    b = 3;
    e = &b;

    prints("Passing pointers to function f!\n");
    prints("Value passed to function: ");
    printi(b);
    prints("\n");
    a = f(e);
    prints("Value returned from function s is: ");
    printi(a);
    prints("\n");
    
    prints("Read an integer!!");
    prints("\n");
    b = readi(e);
    prints("The integer that was read is:");
    printi(b);
    prints("\n");
    
    return 0;
}
开发者ID:aishikchakraborty,项目名称:TinyC-Compiler,代码行数:28,代码来源:ass6_13CS30041_test1.c

示例8: main

//A test file to test the library functions written
int main()
{
    int n,err=0;
    prints("Write the integer n:");
    n = readi(&err);
    if(err!=ERR)
    {
        prints("The integer read is : ");
        printi(n);
    }
    else
    {
        prints("Wrong Input\n");
    }
    float x;

    prints("\nEnter the decimal number: ");
    err = readf(&x);
    if(err==OK)
    {
        prints("The floating number is :");
        printd(x);
    }
    else
    {
        prints("Wrong Input\n");
    }
    prints("\n");
    return 0;
}
开发者ID:nishkarsh-shastri,项目名称:Compilers_assignments_2014,代码行数:31,代码来源:mainFile.c

示例9: dirlink

int dirlink(struct inode *dp, char *dirname, uint32_t ino)
{
    if(!ISDIR(dp->mode) || ino < 1) {
        return -1;
    }
    
    if(dirlookup(dp, dirname, 0)) 
        return -1;

    struct dirent dir;
    int off;
    for(off = 0; off < dp->size; off+=sizeof(struct dirent))
    {
        if(!readi(dp, (char *)&dir, off, sizeof(struct dirent))) {
            return -1;
        }
        // found a new entry
        if(!dir.ino)
            break;
    }
    
    dir.ino = ino;
    strcpy(dir.name, dirname);
    writei(dp, (char *)&dir, off, sizeof(struct dirent));
    return 0;
}
开发者ID:Turingwy,项目名称:turinux,代码行数:26,代码来源:dirent.c

示例10: dirlookup

// Look for a directory entry in a directory.
// If found, set *poff to byte offset of entry.
struct inode*
dirlookup(struct inode *dp, char *name, uint *poff)
{
  uint off, inum;
  struct dirent de;

  if(dp->type != T_DIR)
    panic("dirlookup not DIR");

  for(off = 0; off < dp->size; off += sizeof(de)){
    if(readi(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
      panic("dirlink read");
    if(de.inum == 0)
      continue;
    if(namecmp(name, de.name) == 0){
      // entry matches path element
      if(poff)
        *poff = off;
      inum = de.inum;
      return iget(dp->dev, inum);
    }
  }

  return 0;
}
开发者ID:gaohannk,项目名称:xv6-system,代码行数:27,代码来源:fs.c

示例11: fileread

// Read from file f.
int
fileread(struct file *f, char *addr, int n) {
	int r;

	if (f->readable == 0) {
		return -1;
	}

	if (f->type == FD_PIPE) {
		return piperead(f->pipe, addr, n);
	}

	if (f->type == FD_INODE) {
		ilock(f->ip);

		if ((r = readi(f->ip, addr, f->off, n)) > 0) {
			f->off += r;
		}

		iunlock(f->ip);
		return r;
	}

	panic("fileread");
}
开发者ID:Tachibana-General-Laboratories,项目名称:lainos-fail,代码行数:26,代码来源:file.c

示例12: log_initialize

void
log_initialize()
{
  struct inode *ip;
  uchar buffer[512];
  int i, j;
  struct buf *bp;
  struct trans_start t_blk;

  for(j=0;j<512;j++)
    buffer[j] = 0;

  ip = iget(1, 3);
  ilock(ip);
  if(ip->size < 512*20){
    cprintf("Creating Journal...\n");
    for(i=0;i<20;i++){
      writei(ip, buffer, i*512, sizeof(buffer));
    }
  }
  else {
    readi(ip, &t_blk, 0, sizeof(t_blk));

    if(t_blk.state == LOGGING){
      cprintf("Inconsistency found in file system. Attempting to recover.\n");

      for(i = 0; i < t_blk.num_blks; i++){
    	  readi(ip, buffer, i*512+512, sizeof(buffer));
    	  bp = bread(1, t_blk.sector[i]);
    	  cprintf("Recovering data in sector: %d\n", t_blk.sector[i]);
    	  memmove(bp->data, buffer, sizeof(buffer));
    	  bwrite(bp);
    	  brelse(bp);
      }

      writei(ip, buffer, 0, sizeof(buffer));
      cprintf("Recovery Complete.\n");
    }
  }

  iunlock(ip);
}
开发者ID:fenster,项目名称:xv6-staus-treffert,代码行数:42,代码来源:logfs.c

示例13: main

int main(){
	int n1,result;int *ep;int temp;
	prints("Program to calculate factorial of a number:\n");
	prints("Enter n1:");
	n1=readi();
	result=factorial(n1);
	prints("The factorial of the given number is:");
	printi(result);
	prints("\n");
	return 0;
}
开发者ID:shubhamsaxena02,项目名称:compiler-assignments,代码行数:11,代码来源:ass6_12CS30032_test_5.c

示例14: j_init

void
j_init()
{
  struct inode *ip;
  uchar buffer[512];
  int i, j;
  struct buf *bp;
  struct t_start_blk t_blk;
  
  for(j=0;j<512;j++)
    buffer[j] = 0;
  
  ip = iget(1, 3);
  ilock(ip);
  if(ip->size < 512*20){ 
    cprintf("alloc journal\n");
    // allocate journal if too small
    for(i=0;i<20;i++){
      writei(ip, buffer, i*512, sizeof(buffer));
    }
  }
  else {
    readi(ip, &t_blk, 0, sizeof(t_blk));
    // check if there is a valid not commited transaction
    if(t_blk.state == READY){
      cprintf("~~~~~~~~~~RECOVERING!!!!!~~~~~~~~~~\n");
      for(i = 0; i < t_blk.num_blks; i++){
	readi(ip, buffer, i*512+512, sizeof(buffer));
	bp = bread(1, t_blk.sector[i]);
	cprintf("recovering sector %d\n", t_blk.sector[i]);
	memmove(bp->data, buffer, sizeof(buffer));
	bwrite(bp);
	brelse(bp);
      }
      writei(ip, buffer, 0, sizeof(buffer));
      cprintf("~~~~~RECOVERY COMPLETE~~~~~~~~\n");
    }
  }
  
  iunlock(ip);
}
开发者ID:alangenfeld,项目名称:xv6,代码行数:41,代码来源:journal.c

示例15: main

int main()
{
	int a[100];
	int i;
	int j;
	int n;
	int err;
	prints("Enter the total number of integers to sort :");
	n = readi(&err);
	prints("Enter the number one by one:\n");
	for(i=0;i<n;i++)
	{
		a[i] = readi(&err);
	}

	prints("Sorting the array. \n");
	int temp;
	for(i=n;i>0;i--)
	{
		for(j=0;j<i-1;j++)
		{
			if(a[j+1]<a[j])
			{
				temp = a[j];
				a[j] = a[j+1];
				a[j+1]=temp;
			}
		}
	}
	prints("Printing the sorted array. \n");
	for(i=0;i<n;i++)
	{
		printi(a[i]);
		prints(" ");
	}
	prints("\n");

	return 0;


}
开发者ID:nishkarsh-shastri,项目名称:Compilers_assignments_2014,代码行数:41,代码来源:ass6_12CS10034_test1.c


注:本文中的readi函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。