Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7688329
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: C/C++

2010-09-17 17:57:44

 

#include

 

#define M 3

#define N 4

 

int main(){

       int a[N][M];

       int b[M][N];

       int i,j;

       printf("Please Input %d*%d intergers:\n",M,N);

       for(i=0;i

              for(j=0;j

                     scanf("%d",&a[i][j]);

              }

       }

 

       for(i=0;i

              for(j=0;j

                     b[j][i]=a[i][j];

              }

       }

 

       for(i=0;i

              for(j=0;j

                     printf("%d\t",b[i][j]);

              }

       printf("\n");

       }

}

 

#include

 

int main(){

       char str[5] = {'a','b','c','d','e'};

       for(int i=0;i<5;i++){

              printf("%c\t",str[i]);

       }

       printf("\n");

}

 

 

#include

#include

 

int main()

{

      FILE *fp;

      int ch;

      fp = fopen("./test", "w+");

      if(fp==NULL)

      {

           perror("Open text failed");

           exit(1);

      }

      while((ch=getchar())!='\n')

      {

           fputc(ch,fp);

      }

      rewind(fp);

      printf("Input: ");

      while((ch=fgetc(fp))!=EOF)

      {

           putchar(ch);         

      }

      printf("\n");

      fclose(fp);

      return 0;

}

 

#include

#include

int main()

{

      FILE *fp;

      int i,ch,n;

      fp = fopen("./test","r");

      if(fp==NULL)

      {

           perror("Open test failed");

           exit(1);

      }

      for(i=0;i<=7;i+=2)

      {

           fseek(fp,i,SEEK_SET);

           n = ftell(fp);

           printf("Position :%d\n",n+1);

           ch =fgetc(fp);

           printf("Character: ");

           putchar(ch);

           printf("\n");          

      }

      fclose(fp);

      return 0;   

}

 

 

#include

#include

#define size 256

int main()

{

      char buffer[size];

      int c;

      FILE *fp;

      fp=fopen("test","r");

      if(fp==NULL)

      {

           perror("Open test failed");

           exit(1);

      }

      c=1;

      while((fgets(buffer,size,fp))!=NULL)

      {        

           printf("%d: %s\n",c++,buffer);         

      }

      fclose(fp);

      return 0;

}

 

 

#include

#include

#define size 256

int main(int argc, char **argv)

{

      char buffer[size];

      FILE *fp1,*fp2;

      if(argc!=3)

      {

           printf("Too fewargument\n");

      }

      fp1=fopen(argv[1],"r");   

      if(fp1==NULL)

      {

           perror("Open file1 failed");

           exit(1);

      }

      fp2=fopen(argv[2],"w");  

      if(fp2==NULL)

      {

           perror("Open file2 failed");

           exit(1);

      }

      while(!feof(fp1))

      {

      fgets(buffer,size,fp1);

      fputs(buffer,fp2);

      }

      fclose(fp1);

      fclose(fp2);

      printf("Done!\n");

      return 0;

}

 

 

#include

#include

#define N 3

 

struct student

{

      int id;

      int score;

};

 

int main()

{

      struct student array[N];

      int i,n;

      FILE *fp;

      fp = fopen("./test","w");

      if(fp==NULL)

      {

           perror("Open file failed");

           exit(1);

      }

      for(i=0;i

      {

           printf("ID: ");

           scanf("%d",&array[i].id);

           printf("Score: ");

           scanf("%d",&array[i].score);

      }

      n = fwrite(array,sizeof(struct student),N,fp);

      if(n!=N)

      {

           printf("Write file error");

      }   

      fclose(fp);

      printf("Write Done!\n");

      return 0;

}

 

 

#include

#include

#define N 3

 

struct student

{

      int id;

      int score;

};

 

int main()

{

      struct student array[N];

      int i,n;

      FILE *fp;

      fp = fopen("./test","r");

      if(fp==NULL)

      {

           perror("Open file failed");

           exit(1);

      }

     

      n = fread(array,sizeof(struct student),N,fp);

      if(n!=N)

      {

           if(feof(fp))

           printf("End of file ");

           else         

           printf("read file error");         

      }   

      printf("ID\tScore\n");

      for(i=0;i

      {

           printf("%d\t%d\n",&array[i].id,&array[i].score);

      }

      fclose(fp);

      printf("Read Done!\n");

      return 0;

}

 

 

 

阅读(2059) | 评论(0) | 转发(3) |
0

上一篇:嵌入式学习笔记

下一篇:uboot启动流程

给主人留下些什么吧!~~