ale akonahle do premenej char nacitam nejaku vetu tak mi vypise prve slovo vety 2x a nic viac vedel by mi niekto pomoct ??
Funkcne s vopred zadanou vetou
Kód: Vybrať všetko
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
char str[100] ="Veta na rozdelenie";
char * pch;
cout<<"Veta ktoru ste zadali:\n"<<str;
pch = strtok (str," ,.-");
while (pch != NULL)
{
cout<<"\n"<<pch;
pch = strtok (NULL, " ,.-");
}
getch ();
return 0;
}Nefunkcne veta nacitana z klavesnice
Kód: Vybrať všetko
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
char str[100];
char * pch;
cout<<"Zadaj vetu:\n";
cin>>str;
cout<<"Veta ktoru ste zadali:\n"<<str;
pch = strtok (str," ,.-");
while (pch != NULL)
{
cout<<"\n"<<pch;
pch = strtok (NULL, " ,.-");
}
getch ();
return 0;
}