Скопировать содержимое текстового файла, удалив в каждой строке слова четной длины — C++(Си)

#include <stdio.h>	
#include <string.h>	
#include <stdlib.h>	
 
void main(void)	
{
	char SourceString[] = "AA BBB C DDDD EEEEE";	
	char Separators[]   = " \n.,\t";	
	char *TakeWord;	
 
	char *pathFileInput;	
	char *pathFileOutput;	
 
	FILE *fileInput; 
	FILE *fileOutput; 
 
	pathFileInput = (char*)calloc(20, sizeof(char)); 
	pathFileOutput = (char*)calloc(20, sizeof(char)); 
	printf("Input file path  -> ");	
	scanf("%s", pathFileInput);	
 
	printf("Output file path -> ");	
	scanf("%s", pathFileOutput);	
 
	fileInput = fopen(pathFileInput, "rt"); 
	fileOutput = fopen(pathFileOutput, "wt"); 
 
	while (!feof(fileInput))
	{
		fgets(SourceString, 255, fileInput); 
		TakeWord = strtok(SourceString, Separators); 
 
		while(TakeWord != NULL) 
		{
			if (strlen(TakeWord) % 2 != 0)	
			{
				fputs(TakeWord, fileOutput);	
				fputc(' ', fileOutput);	
			}
			TakeWord = strtok(NULL, Separators);
		}
 
		fputc('\n', fileOutput);
	}
 
	fclose(fileInput); 
	fclose(fileOutput); 
 
	free(pathFileInput);
	free(pathFileOutput);
}

Leave a Comment