إعـــــــلان

تقليص
لا يوجد إعلان حتى الآن.

cat series

تقليص
X
 
  • تصفية - فلترة
  • الوقت
  • عرض
إلغاء تحديد الكل
مشاركات جديدة

  • cat series


    ضعيف اكيد من غير حتي فنكشن لانه الفيرجن الاول
    cat v0.1 by storm_man
    Gre8s goes to strikerX and hell
    كود PHP:
    #include<stdio.h>
    #include<unistd.h>
    #include<string.h>

    #define BUF 250

    void help(char *string);
    main(int argcchar **argv)
    {
             
    int c;
             
    FILE *fp;
             
    char buffer[BUF];
             
    char *file_name;
             
    opterr=0;
             if(
    argc<2)
             {
                       
    help(argv[0]);
                       }
             while((
    c=getopt(argc,argv,"r:"))!=-1)
             {
                                                  switch(
    c)
                                                  {
                                                           case 
    'r':
                                                               
    file_name=strdup(optarg);
                                                               if((
    fp=fopen(file_name,"r"))==NULL)
                                                               {
                                                                                                  
    fprintf(stderr,"\nError In opining File\n");
                                                                                                  exit(
    1);
                                                                                                  }
                                                                                                  while((
    fgets(buffer,BUF,fp))!=NULL)
                                                         {

                                                                                                                                    
    printf("\n%s",buffer);
                                                                                                                                     }
                                                                                                                                     }
                                                                                                                                     }
                                                                                                                                     
    fclose(fp);
                                                                                                                                     }                                                           
                                                                                     
    void help(char *string)
    {
         
    fprintf(stderr,"%s -r filename",string);
         } 
    BOOOF , I AM GONE
    Still , you gotta wait for my PRESENT :D
    C programming arabic Tutorial|Programming-fr34ks

  • #2
    كود PHP:
    #include<stdio.h>
    #include<string.h>
    #include<unistd.h>

    #define BUF 250

    char read_file(char *file_name);
    char write_file(char *file_name);
    void help(char *string);

    main(int argc,char **argv)
    {
    int c;
    char *file_name;
    if(
    argc<2||argc>3)
    {
              
    help(argv[0]);

              }
    while((
    c=getopt(argc,argv,"r:w:h"))!=-1)
    {
                                         switch(
    c)
                                         {
                                                  case 
    'r':
                                                     
    file_name=strdup(optarg);
                                                     
    read_file(file_name);/* inside there is a while loop for reading the file this function only called onec"*/
                                                       
    break;
                                                       case 
    'w':
                                                            
    file_name=strdup(optarg);
                                                            
    write_file(file_name);/* inside there is a while loop for writing in the file this function only called onec*/
                                                       
    case 'h':
                                                            
    help(argv[0]);
                                                            break;
                                         
                                                  }
                                                  }
                                                  }
    char read_file(char *file_name)
    {
         
    FILE *fp;
         
    fp=fopen(file_name,"r");
         if(
    fp==NULL)
         {
         
    fprintf(stderr,"Couldn't open File %s\n",file_name);
         exit(
    1);
                     }
         
    char buffer[BUF];
         
    printf("\n========================Reading======================\n");
         while((
    fgets(buffer,250,fp))!=NULL)
         {
         
    printf("%s",buffer);
         }
                      
    fclose(fp);
                      }
                                            
     
    char write_file(char *file_name)
     {
     
    FILE *fp;
         
    fp=fopen(file_name,"w");
         if(
    fp==NULL)
         {
                    
    fprintf(stderr,"Couldn't open File %s\n",file_name);
                    exit(
    1);
                     }
          
    char buffer[BUF];
           
    printf("\n========================writing (:wq!) for exit ======================\n");
          while((
    fgets(buffer,BUF,stdin))!=NULL)
          {
          if(
    strstr(buffer,":wq!"))
          {
          exit(
    0);
          }
                                                                        
          
    fputs(buffer,fp);
          }
          
    fclose(fp);
          }
     
     
     
    void help(char *string)
    {
         
    fprintf(stderr,"\nfor reading %s -r filename\nfor writing %s -w file_name\nfor help  %s -h\n(only one operation at one)\n",string,string,string);
         exit(
    0);
         } 
    for sofy and ray and radine and "you strikerX my best friend and brother ever"
    الوظيفه واضحه من العنوان
    cat ماشي
    BOOOF , I AM GONE
    Still , you gotta wait for my PRESENT :D
    C programming arabic Tutorial|Programming-fr34ks

    تعليق


    • #3
      another version with indentation and with more error handling functions
      كود PHP:
      #include<stdio.h>
      #include<string.h>
      #include<unistd.h>

      #define BUF 250

      char read_file(char *file_name);
      char write_file(char *file_name);
      void help(char *string);

      main(int argc,char **argv)
      {
      int c;/* for getopt*/
      char *file_name;/*geting file name pointer*/
      if(argc<2||argc>3)/* check for input*/
      {
                
      help(argv[0]);
      }

      while((
      c=getopt(argc,argv,"r:w:h"))!=-1)
      {
                        switch(
      c)
                        {
                           case 
      'r':
                           
      file_name=strdup(optarg);/* allocate space and copy file name into file_name pointer by strdup*/
                           
      read_file(file_name);/* inside there is a while loop for reading the file this function only called onec"*/
                           
      break;
                           
                          case 
      'w':
                          
      file_name=strdup(optarg);
                          
      write_file(file_name);/* inside there is a while loop for writing in the file this function only called onec*/
                          
      break;
                                                         
                         case 
      'h':
                         
      help(argv[0]);/* display help*/
                         
      break;
                         
                         default:
                         
      fprintf(stderr,"Unknown Option -%c",optopt);
                         break;
                                           
                        }
      /* switch end*/
         
      }/* while getopt end*/
      }/* end of main*/


      /* rea file function*/
      char read_file(char *file_name)
      {
           
      FILE *fp;
           
      char buffer[BUF];
           if((
      fp=fopen(file_name,"r"))==NULL)
           {
                
      fprintf(stderr,"Couldn't open File %s\n",file_name);
                exit(
      1);
           }
           
       
           
      printf("\n========================Reading======================\n");
           
            while((
      fgets(buffer,250,fp))!=NULL)
           {
                   
      printf("%s",buffer);
           }
      fclose(fp);
      }
       
      /* end of read file function*/


      /* write on file function*/                                       
       
      char write_file(char *file_name)
       {
            
      FILE *fp;
            
      char buffer[BUF];
                if((
      fp=fopen(file_name,"w"))==NULL)
                {
                          
      fprintf(stderr,"Couldn't open File %s\n",file_name);
                          exit(
      1);
                }
            
             
      printf("\n========================writing (:wq!) for exit ======================\n");
            
                  while((
      fgets(buffer,BUF,stdin))!=NULL)
                   {
                         if(
      strstr(buffer,":wq!"))
                           {
                               exit(
      0);
                            }
                                                                          
                        
      fputs(buffer,fp);
                   }
                    
      fclose(fp);
      }
       
       
      /* end of write on file function*/


      /*display help*/
      void help(char *string)
      {
           
      fprintf(stderr,"\nfor reading %s -r filename\nfor writing %s -w file_name\nfor help  %s -h\n(only one operation at one)\n",string,string,string);
           exit(
      0);
      }
                  
      /*end of display help*/

      /*---EOF---*/ 
      BOOOF , I AM GONE
      Still , you gotta wait for my PRESENT :D
      C programming arabic Tutorial|Programming-fr34ks

      تعليق


      • #4
        بارك الله فيك يا ستورم .. مشاريع جميله جدا..
        ^_^
        GCS

        تعليق


        • #5
          tanks CPU
          i hope you like it
          BOOOF , I AM GONE
          Still , you gotta wait for my PRESENT :D
          C programming arabic Tutorial|Programming-fr34ks

          تعليق


          • #6
            it' s much better than linux CAT hehehehe
            thanx 4 the gr8 , keep rocking
            Programming-Fr34ks[dot]NET
            Ma Weblog
            ابدأ بتعلم Python | Ruby
            كتاب البايثون متوافر الآن
            لا اتواجد بهذا المنتدى ... للإتصال

            تعليق


            • #7
              المشاركة الأصلية بواسطة StrikerX مشاهدة المشاركة
              it' s much better than linux CAT hehehehe
              thanx 4 the gr8 , keep rocking
              you r0x :clown:
              thanks man
              BOOOF , I AM GONE
              Still , you gotta wait for my PRESENT :D
              C programming arabic Tutorial|Programming-fr34ks

              تعليق

              يعمل...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎