You are on page 1of 7

#include<stdio.

h>
#include<stdlib.h>
#include<string.h>
// aceasta functie numara toate caracterele
int nr_litere1(int n,char **text)
{
int i,j,count=0;
for(i=0;i<n;i++)
for(j=0;text[i][j]!='\0';j++) //cand v-a intalni sfarsitul randului atunci se va
trece la urmatorul
{count++;}
return (count -n);}

//aceasta functie numara toate caracterele fara spatiu si \n


int nr_litere2(int n,char **text)
{int i,j,count1=0;
for(i=0;i<n;i++)
for(j=0;text[i][j]!='\0' ;j++)
{
if(text[i][j]!='\n' && text[i][j]!=' ')
count1++;}
return count1 ;}

//aceasta functie calculeaza frecventa cu care apare un caracter


float frecventa(int n,char c, char **text )//c este caracterul cautat

{ float f, count;
int i,j,d=0;
count=0;
for(i=0;i<n;i++)
for(j=0;text[i][j]!='\0' ;j++)
if(text[i][j]==c)
count++;
for(i=0;i<n;i++)
for(j=0;text[i][j]!='\0' ;j++)
if((text[i][j]>='a' && text[i][j] <='z') || (text[i][j]>='A' && text[i][j] <='Z') ||
(text[i][j]>='0' && text[i][j] <='9') || text[i][j]=='_' || text[i][j]=='-' || text[i]
[j]=='\"' || text[i][j]=='\'')
d++;
f=(count*100/d);
return f;
}
//aceasta functie afiseaza pe ecran frecventa cu care apare un caracter
void f2(int n,char c, char **text)
{float f;
f=frecventa(n,c,text);
printf("Frecventa lui \"%c\" este %.2f \n",c,f);
}
// aceasta functie calculeaza numarul de cuvinte
float nr_cuvinte(int n,char **text)
{int i,j,k; float count=0;
for(i=0;i<n;i++)
for(j=0;text[i][j]!='\0';j++)

{ if(text[i][j]!=' ' && text[i][j]!='\n')


{if(text[i][j]=='.' || text[i][j]=='?' || text[i][j]=='!'|| text[i]
[j]=='/' ||
text[i][j]=='+' || text[i][j]=='#' || text[i][j]=='-' || text[i][j]==')' || text[i]
[j]=='(' )
{if(text[i][j+1]!=' ' && text[i][j+1]!='\n')
{count++;
for(k=(j+1);text[i][k]!=' ' && text [i][k]!='\0';k++)
j=k;}
else continue;
continue;}
count++;
{if(text[i][j+1]!=' ')
for(k=(j+1);text[i][k]!=' ' && text [i][k]!='\0';k++)
j=k;}}
}
return count;}

// aceasta functie calculeaza toate caracterele care nu formeaza un cuvant


float nr(int n, char **text)
{int i,j;
float count=0;
for(i=0;i<n;i++)
for(j=0;text[i][j]!='\0';j++)
if(!((text[i][j]>='a' && text[i][j] <='z') || (text[i][j]>='A' && text[i][j] <='Z')
|| (text[i][j]>='0' && text[i][j] <='9') || text[i][j]==' ' || text[i]
[j]=='\n'))//acesta conditie verifica daca text[i][j] e diferit de litere sau cifre
if((text[i][j-1]==' ' || text[i][j-1]=='\n' ) && (text[i][j+1]==' ' ||text[i][j1]=='\n' ))

count ++;
return count;}

int main()
{ char buff[200],**text;
int v[200]={0};
int n,i,c;
/* n este numarul de randuri
c este numarul de caractere cu tot cu spatii si \n
cm reprezinta nr mediu de cuvinte pe rand
lm reprezinta lungimea medie a unui cuvant
c2 reprezinta numarul de caractere fara spatii si \n
c3= numarul de cuvinte
c4= numarul de carctere care nu formeaza un cuvant
*/
float cm,lm,c2,c3,c4,f;
scanf ("%d", &n);
if (n>500)
printf("numarul de randuri este prea mare");
text=(char **) calloc(n,sizeof(char *));
fgets(buff,200,stdin);
for(i=0;i<n;i++)
{fgets(buff,200,stdin);
text[i]=(char *) calloc(strlen(buff),sizeof(char *));
text[i]=strdup(buff);}
c=nr_litere1(n,text);

c2=nr_litere2(n,text);
c3=nr_cuvinte(n,text);
cm=c3/n;
printf("%.2f nr mediu de cuvinte pe linie \n",cm);
c4=nr(n,text);
c4=c2-c4;
lm=c4/c3;
printf("%.2f lungime medie cuvant \n",lm);
printf("%d numar total caractere cu spatii \n",c);
printf("%.0f numar total caractere fara spatii \n",c2);
f2(n,'a',text);
f2(n,'b',text);
f2(n,'c',text);
f2(n,'d',text);
f2(n,'e',text);
f2(n,'f',text);
f2(n,'g',text);
f2(n,'h',text);
f2(n,'i',text);
f2(n,'j',text);
f2(n,'k',text);
f2(n,'l',text);
f2(n,'m',text);
f2(n,'n',text);
f2(n,'o',text);
f2(n,'p',text);

f2(n,'q',text);
f2(n,'r',text);
f2(n,'s',text);
f2(n,'t',text);
f2(n,'u',text);
f2(n,'v',text);
f2(n,'w',text);
f2(n,'x',text);
f2(n,'y',text);
f2(n,'z',text);
f2(n,'A',text);
f2(n,'B',text);
f2(n,'C',text);
f2(n,'D',text);
f2(n,'E',text);
f2(n,'F',text);
f2(n,'G',text);
f2(n,'H',text);
f2(n,'I',text);
f2(n,'J',text);
f2(n,'K',text);
f2(n,'L',text);
f2(n,'M',text);
f2(n,'N',text);
f2(n,'O',text);
f2(n,'P',text);

f2(n,'Q',text);
f2(n,'R',text);
f2(n,'S',text);
f2(n,'T',text);
f2(n,'U',text);
f2(n,'V',text);
f2(n,'W',text);
f2(n,'X',text);
f2(n,'Y',text);
f2(n,'Z',text);
f2(n,'0',text);
f2(n,'1',text);
f2(n,'2',text);
f2(n,'3',text);
f2(n,'4',text);
f2(n,'5',text);
f2(n,'6',text);
f2(n,'7',text);
f2(n,'8',text);
f=frecventa(n,'9',text);
printf("Frecventa lui \"9\" este %.2f ",f);
return 0;}

You might also like