fwriteプロジェクト

fwrite.c

#include <stdio.h>
 
struct struct_test{
  int data_i;
  char data_str[10];
};
 
int main(void){
 
  struct struct_test test1;
  FILE *fp;
 
  printf("input data_i:");
  scanf("%d", &test1.data_i);
 
  printf("input data_str:");
  scanf("%s", test1.data_str);
 
  fp = fopen("test.txt", "wb");
  if (fp == NULL){
    printf("Can't open file!\n");
    return -1;
  }
 
  fwrite(&test1, sizeof(test1), 1, fp);
 
  printf("fwrite struct test1.\n");
 
  fclose(fp);
 
  return 0;
 
}
 

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2010年07月08日 15:02