Dzień dobry
Zmagam się obecnie z takim oto zadaniem:
Napisz program, który pobierze od użytkownika łańcuch tekstowy, a następnie policzy ile wyrazów znalazło się w podanym przez użytkownika tekście (wyrazy mogą składać się wyłącznie z liter, oddzielone mogą być dowolnymi znakami, nie będącymi literami). Przyjmij, że długość ciągu wejściowego nie przekroczy 1000 znaków.
Przykładowe wejście:
Podaj tekst:
Przykladowy tekst
Przykładowe wyjście:
2
Rozpisałem kod:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
char tablica1[1001]={0};
int i=0;
int licznik=1;
printf("Podaj tekst :\n");
fgets(tablica1,1001,stdin);
while(tablica1[i] != '\0')
{
if(tablica1[i] == ' ' && ( ( tablica1[i+1]>=65 && tablica1[i+1]<=90 ) || ( tablica1[i+1]>=97 && tablica1[i+1]<=122 ) || tablica1[i+1]=='-' || tablica1[i+1] ==39 ) )
{
licznik++;
}
if(tablica1[i]='.' && ( tablica1[i+1]>=65 && tablica1[i+1]<=90 ) )
{
licznik++;
}
i++;
}
//printf("Elementy tablicy: %d\n",i);
printf("Ostateczny licznik twoich wyrazow wynosi: %d",licznik);
return 0;
}
A teraz podam przykładowe testy, na których wychodzą mi złe wyniki:
Dolor magnam dolor sit sed porro eius. Consectetur modi tempora adipisci quisquam velit. Quiquia adipisci est quiquia consectetur est. Dolor sit etincidunt sit velit. Ipsum dolore ut aliquam sit ipsum adipisci tempora. Quaerat neque non adipisci magnam. Dolor labore velit velit quiquia.Est eius amet est quisquam. Quisquam numquam tempora ut voluptatem non etincidunt sit. Labore dolor aliquam tempora amet modi ut. Neque modi magnam labore. Labore labore ipsum ut est adipisci dolor.Voluptatem modi velit tempora. Adipisci quisquam ipsum tempora sit. Consectetur dolore tempora dolor. Etincidunt magnam quisquam neque neque. Eius non porro non non adipisci modi quisquam. Quiquia consectetur quiquia est adipisci.Etincidunt etincidunt dolorem labore est. Porro modiipsumtempora.Sitadipiscietinciduntlabore.Estadipiscimodialiquamneque.Magnamporroaliquamdolor.Quisquamtemporaadipisciutlabore.Quisquamsitvoluptatemdoloremestipsumipsumporro.Quisquameiuslaborequaerataliquam.Porrositsedporroamet.Dolorev
Wartość podana przez program jest błędna; powinno być 119 a jest 108
TV and the Internet are good because they keep stupid people from spending too much time out in public.-Douglas CouplandTechnology is teaching us to be human again.-Simon MainwaringComputing should be taught as a rigorous - but fun - discipline covering topics like programming, database structures, and algorithms. That doesn't have to be boring. - Geoff MulganTechnology... the knack of so arranging the world that we don't have to experience it.-Max Frisch"Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter." - Eric S. RaymondThe past cannot be changed. The future is yet in your power. - Unknown"The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom." - Isaac AsimovThere was a time in the 1930s when magazinewriterscouldactuallymakeagoodliving.'TheSaturdayEveningPost'and'Collier's'bothhadthreestoriesineachissue.Thesewereusuallyentertaining,andpeoplereallywentforthem.Butthentelevisioncamealong,andnowofcourse,informationtechnology...thenewwayofkillingtime.-TomWolfe
Wartość podana przez program jest błędna; powinno być 144 a jest 135
Podpowiecie mi jakich warunków brakuje w instrukcji warunkowej? :/