Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C/C++ÎļþµÄ²Ù×÷£¨fread() fwrite()£©

freadº¯ÊýºÍfwriteº¯Êý
1.º¯Êý¹¦ÄÜ
  ÓÃÀ´¶Áдһ¸öÊý¾Ý¿é¡£
2.Ò»°ãµ÷ÓÃÐÎʽ
  fread(buffer,size,count,fp);
  fwrite(buffer,size,count,fp);
3.˵Ã÷
  £¨1£©buffer£ºÊÇÒ»¸öÖ¸Õ룬¶ÔfreadÀ´Ëµ£¬ËüÊǶÁÈëÊý¾ÝµÄ´æ·ÅµØÖ·¡£¶ÔfwriteÀ´Ëµ£¬ÊÇÒªÊä³öÊý¾ÝµÄµØÖ·¡£
  £¨2£©size£ºÒª¶ÁдµÄ×Ö½ÚÊý£»
  £¨3£©count:Òª½øÐжÁд¶àÉÙ¸ösize×Ö½ÚµÄÊý¾ÝÏ
  £¨4£©fp:ÎļþÐÍÖ¸Õë¡£
 ×¢Ò⣺1 Íê³É´Îд²Ù(fwrite())×÷ºó±ØÐë¹Ø±ÕÁ÷(fclose());
           2 Íê³ÉÒ»´Î¶Á²Ù×÷(fread())ºó£¬Èç¹ûûÓйرÕÁ÷(fclose()),ÔòÖ¸Õë(FILE * fp)×Ô¶¯ÏòºóÒƶ¯Ç°Ò»´Î¶ÁдµÄ³¤¶È£¬²»¹Ø±ÕÁ÷¼ÌÐøÏÂÒ»´Î¶Á²Ù×÷Ôò½Ó×ÅÉϴεÄÊä³ö¼ÌÐøÊä³ö;
           3 fprintf() £º °´¸ñʽÊäÈëµ½Á÷£¬ÆäÔ­ÐÍÊÇint fprintf(FILE *stream, const char *format[, argument, ...]);ÆäÓ÷¨ºÍprintf()Ïàͬ£¬²»¹ý²»ÊÇдµ½¿ØÖÆ̨£¬¶øÊÇдµ½Á÷°ÕÁË¡£×¢ÒâµÄÊÇ·µ»ØֵΪ´Ë´Î²Ù×÷дÈëµ½ÎļþµÄ×Ö½ÚÊý¡£Èçint c = fprintf(fp, "%s %s %d %f", str1,str2, a, b) ;str1£º10×Ö½Ú£»str2£º 10×Ö½Ú£»a£º2×Ö½Ú£»b£º8×Ö½Ú£¬cΪ33£¬ÒòΪдÈëʱ²»Í¬µÄÊý¾Ý¼ä×Ô¶¯¼ÓÈëÒ»¸ö¿Õ¸ñ¡£
ÎļþʹÓÃÖ®ºóÒ»¶¨Òª¹Ø±Õ,·ñÔò½«²»ÄÜÕýÈ·ÏÔʾÄÚÈÝ.fwrite:¶ÁÈëÁ½¸öѧÉúÐÅϢȻºóÓÃfwrite´æÈëÎļþ
fread:ÓÃfread´ÓÎļþÖжÁ³öѧÉúÐÅÏ¢¡£
fwrite.c
#include <stdio.h>
#define SIZE 2
struct student_type
{
 char name[10];
 int num;
 int age;
 char addr[10];
}stud[SIZE];
void save()
{
 FILE *fp;
 int i;
 if((fp=fopen("stu_list","wb"))==NULL)
 {
  printf("cant open the file");
  exit(0);
 }
 for(i=0;i<SIZE;i++)
 {
   if(fwrite(&stud[i],sizeof(struct student_type),1,fp)!=1)
    printf("file write error\n");
 }
 fclose(fp);
}
main()
{
 int i;
 for(i=0;i<SIZE;i++)
 {
   scanf("%s%d%d%s",&stud[i].name,&stud[i].num,&stud[i].age,&stud[i].addr);
   save();
 }
 for(i=0;i<SIZE;i++)
 {
   printf("%s,%


Ïà¹ØÎĵµ£º

±àд¿ÉÒÆÖ²C/C++³ÌÐòÒªµã

      1.·Ö²ãÉè¼Æ£¬¸ôÀëƽ̨Ïà¹ØµÄ´úÂë¡£¾ÍÏñ¿É²âÊÔÐÔÒ»Ñù£¬¿ÉÒÆÖ²ÐÔÒ²Òª´ÓÉè¼Æ×¥Æð¡£Ò»°ãÀ´Ëµ£¬×îÉϲãºÍ×îϲ㶼²»¾ßÓÐÁ¼ºÃµÄ¿ÉÒÆÖ²ÐÔ¡£×îÉϲãÊÇ
GUI£¬´ó¶àÊýGUI¶¼²»ÊÇ¿çƽ̨µÄ£¬ÈçWin32 SDKºÍMFC¡£×îϲãÊDzÙ×÷ϵͳAPI£¬´ó¶à²¿·Ö²Ù×÷ϵͳAPI¶¼ÊÇרÓõġ£
¡¡¡¡
Èç¹ûÕâÁ½²ãµÄ´úÂëÉ¢²¼ÔÚÕû¸öÈí¼ ......

dz̸C/C++ÄÚ´æй©¼°Æä¼ì²â¹¤¾ß

BoundsChecker²ÉÓÃÒ»ÖÖ±»³ÆΪ Code InjectionµÄ¼¼Êõ£¬À´½Ø»ñ¶Ô·ÖÅäÄÚ´æºÍÊÍ·ÅÄÚ´æµÄº¯ÊýµÄµ÷Ó᣼òµ¥µØ˵£¬µ±ÄãµÄ³ÌÐò¿ªÊ¼ÔËÐÐʱ£¬BoundsCheckerµÄDLL±»×Ô¶¯ÔØÈë½ø³ÌµÄµØÖ·¿Õ¼ä£¨Õâ¿ÉÒÔͨ¹ýsystem-levelµÄHookʵÏÖ£©£¬È»ºóËü»áÐ޸Ľø³ÌÖжÔÄÚ´æ·ÖÅäºÍÊͷŵĺ¯Êýµ÷Óã¬ÈÃÕâЩµ÷ÓÃÊ×ÏÈתÈëËüµÄ´úÂ룬ȻºóÔÙÖ´ÐÐÔ­À´µÄ´úÂë¡£Bo ......

ANSI CÓ¦ÓóÌÐòÉè¼Æ

1£¬´«Öµµ÷ÓÃ
ÿ¸öʵ²Î¶¼ÊÇÒ»¸ö±í´ïʽ£¬¶¼ÓÐÒ»¸öÖµ¡£Í¨¹ý¸´ÖƱí´ïʽֵµÄ·½Ê½£¬½«Æä´æ´¢ÔÚÒ»¸öÁÙʱµ¥ÔªÖУ¬²¢°Ñ¶ÔÓ¦µÄÐÎʽ²ÎÊý×÷ΪÕâ¸öµ¥ÔªµÄ±êʶ·û¡£¸Ã´«µÝʵ²Î·½·¨±»³Æ×÷´«Öµµ÷Óá£call by value
2£¬Ô¤´¦ÀíÆ÷
±àÒëÆ÷°Ñ³ÌÐòת»»ÎªÄ¿±ê´úÂë֮ǰÏÈÓÉCÔ¤´¦ÀíÆ÷´¦ÀíÔ´Îļþ¡£
CÔ´´úÂë->Ô¤´¦ÀíÆ÷->±àÒëÆ÷
Ô¤´¦ÀíÆ÷Ö´Ðг ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ