Advertisement
mityapwnz

Untitled

Dec 18th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int WordIndex(char* str,int n){
  5. int count=0,i=0;
  6. for(;(count<n-1)&&str[i]!='\0';i++){
  7. if((str[i]==' ')&&(str[i+1]!=' ')){
  8. count++;
  9. cout<<str[i]<<endl;
  10. if(str[i]=='\0')
  11. break;
  12. }
  13. }
  14. if(str[i]=='\0') return -1;
  15. else
  16. return i;
  17. }
  18.  
  19. main(){
  20. char input[256];
  21. int n;
  22. cin.getline(input,256);
  23. cin>>n;
  24. cout<<"i="<<WordIndex(input,n)<<endl;
  25. system("pause");
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement