Advertisement
xeritt

Delete from file string with digit

Nov 29th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <ctype.h>
  6. #define N 1024
  7.  
  8. int check_str(uint8_t *str){
  9.     for (int i=0; i<strlen((char*)str); i++){
  10.         if (isdigit(str[i])>0){
  11.             return 1;
  12.         }  
  13.     }  
  14.     return 0;
  15. }
  16.  
  17. int main (int argc, char **argv)
  18. {
  19.     if (argc < 3) {
  20.         printf("Wrong count of params. Usage ./command [file_src_name] [file_dest_name]\n");
  21.         exit(1);
  22.     }
  23.  
  24.     FILE *fp, *fp2;
  25.     if ((fp = fopen (argv[1], "r")) == NULL)
  26.     {
  27.         printf ("Error open file.\n");
  28.         exit (1);
  29.     }
  30.  
  31.     if ((fp2 = fopen (argv[2], "w")) == NULL)
  32.     {
  33.         printf ("Error open file.\n");
  34.         exit (1);
  35.     }
  36.  
  37.     uint8_t buffer[N];
  38.     while(!feof(fp)) {
  39.         memset(buffer, '\0',N);
  40.         if(fgets((char*)buffer, N, fp))
  41.         {
  42.             if (0 == check_str(buffer))
  43.             {
  44.                 fputs((char*)buffer, fp2);
  45.                 printf("%s", buffer);
  46.             }
  47.         }
  48.     }
  49.     fclose (fp2);
  50.     fclose (fp);
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement