Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int search(const char* SInputFile, char* max_word)
- {
- char word[256];
- int k,bul,len,max_len;
- char* p;
- FILE* in;
- in=fopen(SInputFile,"r");
- if (in==NULL)
- return -1;
- max_len = 0;
- while ((k = fscanf(in,"%[A-z]",word)) != EOF)
- {
- if (k == 0)
- fgetc(in);
- else
- {
- len = strlen(word);
- if (word[len - 1] == 'E')
- {
- bul = 1;
- for (*p = word; *p; p++)
- if (*p < 'A' || *p > 'Z')
- {
- bul= 0;
- break;
- }
- if (bul == 1 && max_len < len)
- {
- max_len =len;
- strncpy(max_word, word, sizeof max_word);
- }
- }
- }
- }
- return 0;
- }
- int main(void)
- {
- FILE*out;
- out=fopen("data2.txt","w");
- char SInputFile[]="data.txt";
- char max_word[256];
- int k;
- k=search(SInputFile,max_word);
- if (k==-1)
- {
- printf("=Can't open the file");
- return 1;
- }
- fprintf(out,"Word with a max length: %s\n", max_word);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement