Home > Archives > 2010-01

2010-01

OSの課題

  • 2010-01-31 (Sun)
  • Prog

01.c
03.c
04.c

課題01

#include <stdio.h>

main() {
  int i;
  FILE *fp, *fp2;
  if((fp=fopen("char.dat","w"))==NULL) {
    printf("file open error\n");
    exit(1);
  }
  if((fp2=fopen("binary.dat","wb"))==NULL) {
    printf("file open error\n");
    exit(1);
  }

  for(i=1000;i<=10000;i+=1000) {
    fprintf(fp,"%d",i);
    fwrite(&i,2,1,fp2);
    if(i!=10000) {
      fprintf(fp,","); fprintf(fp2,",");
    }
  }
  fclose(fp); fclose(fp2);
}

課題03

#include <stdio.h>

main() {
  FILE *fp, *fp2;
  int i;
  int pos, d;
  if((fp=fopen("char.dat","r"))==NULL) {
    printf("file open error\n");
    exit(1);
  }
  scanf("%d",&pos);
  for(i=0;i<pos;i++) fscanf(fp, "%d,", &d);
  printf("Seq = %d\n",d);

  fseek(fp,5*(pos-1),0);
  fscanf(fp, "%d", &d);
  printf("Direct = %d\n",d);

  fclose(fp);
}

課題04

#include <stdio.h>

main() {
  FILE *fp, *fp2;
  int i;
  int pos, d;
  if((fp=fopen("binary.dat","rb"))==NULL) {
    printf("file open error\n");
    exit(1);
  }
  scanf("%d",&pos);
  for(i=0;i<pos;i++) {
    if(i!=0) fread(&d,1,1,fp); // for ','
    fread(&d,2,1,fp);
  }
  printf("Seq = %d\n",d);

  fseek(fp,2*(pos-1)+pos-1,0);
  fread(&d,2,1,fp);
  printf("Direct = %d\n",d);

  fclose(fp);
}

OAuthのFramework for Objective-C

NSDate を NSString から

Home > Archives > 2010-01

Search
Feeds
Meta

Return to page top