Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.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 main() {
- writeToFile();
- FILE *dat = fopen("text.txt", "r");
- FILE *dat1 = fopen("print.txt", "w");
- char c;
- char zbor[50];
- int i = 0;
- while (( c = fgetc ( dat )) != EOF ) {
- //ako zborot sodrzi bukvi ili cifri se koristi isalnum, ako sodrzi samo cifri se koristi isdigit, a ako ima samo bukvi togas isalpha
- if ( isalnum (c )) {
- zbor[i] = c;
- i++;
- } //vo else-ot zborot zavrsuva
- else {
- zbor[i] = '\0';
- //proveruvame dali zborot e palindrom
- if( i > 0){
- int k;
- int flag = 1;
- for(k=0; k<i/2; k++){
- if(tolower(zbor[k]) != tolower(zbor[i-k-1])){
- flag = 0;
- break;
- }
- }
- if(flag == 1){
- fprintf(dat1, "%s\n", zbor);
- }
- }
- i=0;
- }
- }
- fclose(dat);
- fclose(dat1);
- printFile();
- return 0;
- }
Add Comment
Please, Sign In to add comment