Advertisement
Guest User

plagijat

a guest
Jan 21st, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.00 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<ctype.h>
  4. #include <stdlib.h>
  5.  
  6. void writeToFile() {
  7.     FILE *f = fopen("dat.txt", "w");
  8.     char c;
  9.     while((c = getchar()) != '#') {
  10.         fputc(c, f);
  11.     }
  12.     fclose(f);
  13. }
  14.  
  15. int petbukvi( char * red ){
  16.     int count = 0;
  17.    
  18.     while ( *red ){
  19.         if (isalpha(*red)){
  20.             count++;
  21.         }
  22.         if ( count > 4 ){
  23.             return 1;
  24.             red++;
  25.         }
  26.     }
  27.    
  28.     return 0;
  29. }
  30.  
  31. void printRow ( char * red, int first, int last ){
  32.    
  33.     for ( int i = first; i <= last; i++ ){
  34.         if ( i == first ){
  35.             printf("%c", toupper(red[i]));
  36.         }
  37.         else if ( i == last ){
  38.             printf("%c", tolower(red[i]));
  39.         }
  40.         else{
  41.             printf("%c", red[i]);
  42.         }
  43.        
  44.     }
  45. }
  46.  
  47. void najdiPrvPosleden( char *red ){
  48.    
  49.     int flag=0, i=0, first, last;
  50.    
  51.     if (isalpha(red[i])&&flag == 0){
  52.         first = i;
  53.         flag = 1;
  54.     }
  55.     else if ( isalpha(red[i])&&flag ){
  56.         last=i;
  57.     }
  58.     i++;
  59.    
  60. }
  61.  
  62. int main () {
  63.    
  64.     writeToFile();
  65.    
  66.     char red[100], maxRed[100];
  67.     int max=100;
  68.  
  69.     FILE * file;
  70.     if (( file = fopen("dat.txt", "r")) == NULL ){
  71.         printf("Datotekata ne moze da se otvori");
  72.         exit(-1);
  73.     }
  74.    
  75.     while((fgets(red, 100, file)) != NULL){
  76.         if ( petbukvi(red) == 1 && strlen(red) < max ){
  77.         max=strlen(red);
  78.         strcpy(maxRed, red);
  79.     }
  80.     }
  81.    
  82.    
  83.     fclose(file);
  84.     najdiPrvPosleden(maxRed);
  85.    
  86.  
  87.     return 0;
  88. }
  89.  
  90.  
  91. #include<stdio.h>
  92. #include<string.h>
  93. #include<ctype.h>
  94.  
  95.  
  96. void writeToFile() {
  97.     FILE *f = fopen("dat.txt", "w");
  98.     char c;
  99.     while((c = getchar()) != '#') {
  100.         fputc(c, f);
  101.     }
  102.     fclose(f);
  103. }
  104.  
  105. int hasFiveLetter(char *red){
  106.  
  107.     int count = 0;
  108.    
  109.     while(*red){
  110.         if(isalpha(*red))
  111.             count++;
  112.         if(count > 4)
  113.             return 1;
  114.         *red++;
  115.     }
  116.     return -1;
  117.    
  118. }
  119.  
  120. void printRow(char *red, int first, int last){
  121.    
  122.     for(int i = first; i <= last; i++){
  123.         if(i == first){
  124.             printf("%c", tolower(red[i]));
  125.         }
  126.         else if(i == last){
  127.             printf("%c", tolower(red[i]));
  128.         }
  129.         else{
  130.             printf("%c", red[i]);
  131.         }
  132.     }
  133. }
  134.  
  135. void findFirstLast(char *red){
  136.  
  137.     int flag = 0, i = 0, first, last;
  138.    
  139.     while(red[i]){
  140.         if(isalpha(red[i])&&flag == 0){
  141.             first = i;
  142.             flag = 1;
  143.         }
  144.         else if(isalpha(red[i])&&flag == 1){
  145.             last = i;
  146.         }
  147.         i++;
  148.     }
  149.     printRow(red, first, last);
  150. }
  151.  
  152. int main() {
  153.    
  154.     writeToFile();
  155.  
  156.     FILE *file = fopen("dat.txt", "r");
  157.  
  158.     char red[100], maxRed[100];
  159.    
  160.     int maxLen = 0;
  161.    
  162.     while(fgets(red, 100, file) != NULL){
  163.    
  164.         if(hasFiveLetter(red) && strlen(red) >= maxLen){
  165.             maxLen = strlen(red);
  166.             strcpy(maxRed, red);
  167.         }
  168.     }
  169.     fclose(file);
  170.     findFirstLast(maxRed);
  171.    
  172.     return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement