Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define maxi 50
- int prebrojReci(char *);
- //int nadjiNajduzu(char *);
- int nadjiNajduzu2(char *);
- int main(){
- FILE *ulaz,*izlaz;
- char s[maxi];
- int broj=0,max,k=0;
- ulaz=fopen("ulaz.txt","r");
- izlaz=fopen("izlaz.txt","w");
- if(ulaz==NULL)
- {
- printf("nije moguce otvoriti datoteku!!\n");
- return 1;
- }
- while(fgets(s,maxi,ulaz))
- {
- broj+=prebrojReci(s);
- if(k==0)
- {
- max=nadjiNajduzu2(s);
- k=1;
- }
- else
- {
- if(nadjiNajduzu2(s)>max) max=nadjiNajduzu2(s);
- }
- }
- fprintf(izlaz,"od ukupno %d reci, najduza ima %d slova.\n",broj,max);
- fclose(ulaz);
- fclose(izlaz);
- return 0;
- }
- int prebrojReci(char *s)
- {
- int broj=0,i=0;
- while(s[i]!='\0')
- {
- if(s[i]==' ')broj++;
- i++;
- }
- return broj+1;
- }
- /*int nadjiNajduzu(char *s)
- {
- int max=0,i=0,br=0,k=0;
- while(s[i]!='\0')
- {
- if(k==0)
- {
- if(s[i]==' ')
- {
- max=br;
- k=1;
- br=0;
- }
- br++;
- }
- else
- {
- br++;
- if(s[i]==' '||s[i+1]=='\0')
- {
- if(br>max)max=br;
- br=0;
- }
- }
- i++;
- }
- return max-1;
- }*/
- int nadjiNajduzu2(char *s)
- {
- char b[10]="";
- int max,i,j=0,k=0;
- for(i=0;i<=strlen(s);i++)
- {
- if(k==0)
- {
- if(s[i]==' ')
- {
- max=strlen(b);
- k=1;
- b[0]='\0';
- j=0;
- }
- b[j++]=s[i];
- }
- else
- {
- b[j++]=s[i];
- if(s[i]==' ' || i==strlen(s))
- {
- if(strlen(b)>max)max=strlen(b);
- b[0]='\0';
- j=0;
- }
- }
- }
- return max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement