Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int WordIndex(char* str,int n){
- int count=0,i=0;
- for(;(count<n-1)&&str[i]!='\0';i++){
- if((str[i]==' ')&&(str[i+1]!=' ')){
- count++;
- cout<<str[i]<<endl;
- if(str[i]=='\0')
- break;
- }
- }
- if(str[i]=='\0') return -1;
- else
- return i;
- }
- main(){
- char input[256];
- int n;
- cin.getline(input,256);
- cin>>n;
- cout<<"i="<<WordIndex(input,n)<<endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement