Advertisement
mityapwnz

Untitled

Dec 18th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 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)&&(i<strlen(str));i++){
  7.             if((str[i]==' ')&&(str[i+1]!=' ')){
  8.                 count++;
  9.             }
  10.         }
  11.         if(strlen(str)==i)
  12.         return -1;
  13.         else
  14. return i;
  15. }
  16.  
  17. main(){
  18. char input[256];
  19. int n;
  20. cin.getline(input,256);
  21. cin>>n;
  22. cout<<"i="<<WordIndex(input,n)<<endl;
  23. system("pause");
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement