Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int isLegal(char *);
  6.  
  7. int main(int argc, char *argv[]){
  8.  
  9. char words[100];
  10.  
  11. FILE *fp = fopen(argv[1], "r");
  12. if (fp == NULL) {
  13. printf("%s\n", "There was an error opening the file");
  14. return 1;
  15. }
  16. fscanf(fp, "%s", words);
  17. while (!feof(fp)) {
  18. if ( isLegal(words) ) {
  19. printf("%s\n", words);
  20. }
  21. fscanf(fp, "%s", words);
  22. }
  23.  
  24. fclose (fp);
  25. return 0;
  26. }
  27.  
  28. int isLegal(char *words) {
  29. int len = strlen(words);
  30. char foundFlag = 'y';
  31. for (int a=0; a<len; a++) {
  32. if ((words[a] < 'A' || words[a] > 'Z') && (words[a] < 'a' || words[a] > 'z'))
  33. foundFlag = 'n';
  34. }
  35. if (foundFlag == 'n')
  36. return 0;
  37. else
  38. return 1;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement