Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX 100
- #include <ctype.h>
- #include <string.h>
- void writeToFile() {
- FILE *f = fopen("text.txt", "w");
- char c;
- while((c = getchar()) != '#') {
- fputc(c, f);
- }
- fclose(f);
- }
- void printFile() {
- FILE *f=fopen("print.txt","r");
- char line[100];
- while(!feof(f)){
- fgets(line,100,f);
- if (feof(f))
- break;
- printf("%s",line);
- }
- fclose(f);
- }
- int e_palindrom(char c[])
- {
- int i,j,k=0;
- char n[MAX];
- for (i=0;i<strlen(c);i++)
- {
- if (isalpha(c[i]))
- {
- n[k]=c[i];
- k++;
- }
- }
- n[k]='\0';
- for (i=0,j=strlen(n)-1;i<strlen(n);i++,j--)
- {
- if (tolower(n[i])!= tolower(n[j])) return 0;
- }
- for (i=0;i<strlen(n);i++)
- {
- c[i]=n[i];
- }
- c[i]='\0';
- return 1;
- }
- int main() {
- writeToFile();
- char n[MAX];
- FILE *dat1=fopen("text.txt","r");
- FILE *dat2=fopen("print.txt","w");
- while (fscanf(dat1,"%s",n)!=EOF)
- {
- if (e_palindrom(n))
- {
- fprintf(dat2,"%s\n",n);
- }
- }
- fclose (dat1);
- fclose (dat2);
- printFile();
- return 0;
- }
Add Comment
Please, Sign In to add comment