help needed with code

Discussion in 'C++' started by micsom, Oct 23, 2008.

  1. micsom

    micsom New Member

    Joined:
    Oct 13, 2008
    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    I*N*D*I*A*
    friends..i am breaking my head from the morning over a little piece of code..

    the requirement is ..if the input is "MIKE"...it will store the string as MIKE.*
    if the input is "MIKE.TXT"(or any extension)....it will retain the filename with that extension..

    please help me here
     
  2. imrose_suleman

    imrose_suleman New Member

    Joined:
    Oct 18, 2008
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programer in Tata consultancy services
    Location:
    native of hyderabad presently in chennai
    dude....its very easy thing dude ....y r u breaking ur head...
    here is the code...
    try this..
    code:

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    main()
    {
    string s;
    cout<<"enter string"<<endl;
    cin>>s;
    string s1=".*";
    int count=0;
    for(int i=0;i<s.length();i++)
    {
    if(s.at(i)==s1.at(0)) count++;
    }
    if(count==0) s.insert(s.length(),s1);
    cout<<s<<endl;
    }
     
    Last edited by a moderator: Oct 23, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice