Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 1024
- void renameTypeFile(char src[], char dest[], char *needle, char *text){
- int c = strcspn(src, needle);
- strncpy(dest, src, c);
- strcat(dest, text);
- }
- int check_str(uint8_t * str){
- for (int i = 0; i < strlen((char *)str); i++) {
- if (isdigit(str[i]) > 0) {
- return 1;
- }
- }
- return 0;
- }
- int main(int argc, char **argv){
- if (argc < 3) {
- printf("Wrong count of params. Usage ./command [file_src_name] "
- "[file_dest_name]\n");
- exit(1);
- }
- FILE *fp, *fp2;
- if ((fp = fopen(argv[1], "r")) == NULL) {
- printf("Error open file.\n");
- exit(1);
- }
- char str2[N];
- renameTypeFile(argv[1], str2, ".", ".xyz");
- if ((fp2 = fopen(str2, "w")) == NULL) {
- printf("Error open file.\n");
- exit(1);
- }
- int max_str = atoi(argv[2]);
- uint8_t buffer[N];
- int i = 0;
- while (!feof(fp)) {
- memset(buffer, '\0', N);
- if (fgets((char *)buffer, N, fp)) {
- if (i++ >= max_str)
- break;
- if (0 == check_str(buffer)) {
- fputs((char *)buffer, fp2);
- printf("%s", buffer);
- }
- }
- }
- fclose(fp2);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement