Guest User

Untitled

a guest
Feb 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. #define START 0
  6. #define CAPITAL_WORD 1
  7. #define WORD 2
  8. #define DOT 3
  9.  
  10.  
  11. int main()
  12. {
  13.     FILE *datoteka;
  14.     char c, temp[30];
  15.  
  16.  
  17.     if((datoteka = fopen("test.txt", "r")) == NULL ){
  18.         printf("GRESKA!!!");
  19.         return -1;
  20.     }
  21.     c = fgetc(datoteka);
  22.  
  23.     do{
  24.         int count = 0;
  25.         int token = START;
  26.  
  27.         if( c >= 'A' && c <= 'Z'){
  28.             token = CAPITAL_WORD;
  29.             temp[count] = c;
  30.             c = fgetc(datoteka);
  31.             while( c >= 'a' && c <='z' ){
  32.                 count++;
  33.                 temp[count] = c;
  34.                 c = fgetc(datoteka);
  35.             }
  36.             temp[++count] = '\0';
  37.             printf("\nCAPITAL WORD \t\t %s", temp);
  38.         }else if ( c >= 'a' && c <= 'z' ){
  39.             token = WORD;
  40.             while( c >= 'a' && c <= 'z' ){
  41.                 temp[count] = c;
  42.                 count++;
  43.                 c = fgetc(datoteka);
  44.             }
  45.             temp[count] = '\0';
  46.             printf("\nWORD \t\t\t %s", temp);
  47.         }else if( c == ' ' || c == '\n' ){
  48.             c = fgetc(datoteka);
  49.         }else if ( c== '.' ){
  50.             token = DOT;
  51.             printf("\nDOT \t\t\t %c", c);
  52.             c = fgetc(datoteka);
  53.         }else{
  54.             printf("\nError \t\t\t %c", c);
  55.             c = fgetc(datoteka);
  56.         }
  57.  
  58.     }while( c != EOF );
  59.  
  60.  
  61.     return 0;
  62. }
Add Comment
Please, Sign In to add comment