[C] Afisarea si numararea cuvintelor dintr-o fraza

Scrieti un program care realizeaza citirea, afisarea si numararea cuvintelor dintr-o fraza, citita de la consola:

[code]

#include<stdio.h>
#include<string.h>
int main()
{
int m=200,n,i,nrcuv=1,v[m];
char fraza[m];
printf("Scrieti fraza: \\n= ");
gets(fraza);
n = strlen(fraza);
for(i=0;i<=n;i++)
{
if(fraza[i] == ' ')
{
nrcuv++;
v[i] = 1;
}
}
printf("Fraza contine %d cuvinte.\\n",nrcuv);
printf("Cuvintele sunt:\\n");
for(i=0;i<=n;i++)
{
printf("%c",fraza[i]);
if(v[i] == 1)
{
printf("\\n");
}
}
return 0;
}

[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>