|
|
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>
struct MYDATA {
char type_1;
short type_2;
long type_3;
int type_4;
float type_5;
double type_6;
};
int main( int argc, char *argv[] )
{
struct MYDATA md;
int allsize;
printf( "MYDATA の大きさは %d\n", sizeof( struct MYDATA ) );
allsize =
sizeof( char ) +
sizeof( short ) +
sizeof( long ) +
sizeof( int ) +
sizeof( float ) +
sizeof( double );
printf( "MDATA のメンバの大きさの合計は %d\n", allsize );
return 0;
}
| |
|
|
MYDATA の大きさは 24
MDATA のメンバの大きさの合計は 23
| |
|
|
|
|
#include <stdio.h>
struct MYDATA {
char type_1;
short type_2;
long type_3;
int type_4;
float type_5;
double type_6;
};
int main( int argc, char *argv[] )
{
struct MYDATA md;
FILE *fp;
fp = fopen( "MYDATA", "wb" );
if ( fp == NULL ) {
return 1;
}
fwrite( &md, sizeof( struct MYDATA ), 1, fp );
fclose( fp );
return 0;
}
| |
|
|
|
|
#include <stdio.h>
struct MYDATA {
char type_1;
short type_2;
long type_3;
int type_4;
float type_5;
double type_6;
};
int main( int argc, char *argv[] )
{
struct MYDATA md;
FILE *fp;
fp = fopen( "MYDATA", "wb" );
if ( fp == NULL ) {
return 1;
}
md.type_1 = 0;
md.type_2 = 0;
md.type_3 = 0;
md.type_4 = 0;
md.type_5 = 0;
md.type_6 = 0;
fwrite( &md, sizeof( struct MYDATA ), 1, fp );
fclose( fp );
return 0;
}
| |
|
|
|
|
#include <stdio.h>
struct MYDATA {
char type_1;
short type_2;
long type_3;
int type_4;
float type_5;
double type_6;
};
int main( int argc, char *argv[] )
{
struct MYDATA md;
FILE *fp;
fp = fopen( "MYDATA", "wb" );
if ( fp == NULL ) {
return 1;
}
md.type_1 = 8;
md.type_2 = 9;
md.type_3 = 10;
md.type_4 = 11;
md.type_5 = 12;
md.type_6 = 13;
fwrite( &md, sizeof( struct MYDATA ), 1, fp );
fclose( fp );
return 0;
}
| |
|
|
|
|
#include <stdio.h>
struct MYDATA {
char type_1;
short type_2;
long type_3;
int type_4;
float type_5;
double type_6;
};
void WriteMyData( struct MYDATA *pmd, FILE *fp );
int main( int argc, char *argv[] )
{
struct MYDATA md;
FILE *fp;
fp = fopen( "MYDATA", "wb" );
if ( fp == NULL ) {
return 1;
}
WriteMyData( &md, fp );
fclose( fp );
return 0;
}
void WriteMyData( struct MYDATA *pmd, FILE *fp )
{
pmd->type_1 = 8;
pmd->type_2 = 9;
pmd->type_3 = 10;
pmd->type_4 = 11;
pmd->type_5 = 12;
pmd->type_6 = 13;
fwrite( pmd, sizeof( struct MYDATA ), 1, fp );
}
| |
|
|
|