Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:50:54+00:00 2026-06-12T06:50:54+00:00

I keep running into an issue with this code in C++: #include <stdio.h> #include

  • 0

I keep running into an issue with this code in C++:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>

using namespace std;

int main ()
{
   string words[25];
   int i = 0;
   char * word;
   cout << "Input a phrase, no capital letters please.";
   char phrase[100] = "this is a phrase";
   word = strtok (phrase, " ,.");

   while (word != NULL)
   {
      i++;
      words[i] = word;
      cout << words[i] << " ";
      word = strtok (NULL, " ,.-");
      int g = 0;
   }
   cout << endl << endl;

   int g = 0;
   while (g < i)
   {
      g++;
      char f = words[g].at(0);
      if ((f == 'a') || (f == 'e') || (f == 'i') || (f == 'o') || (f == 'u') || (f == 'y'))
      {
         words[g].append("way");
         cout << words[g] << " ";
      }
      else
      {
         words[g].erase (0,1);
         cout << words[g] << f << "ay" << " ";
      }

   }
   cout << endl;
   system("PAUSE");
}

I actually want my program user to generate the phrase to be put in char phrase[100] but I can’t figure out the proper syntax to initiate input on it without screwing up the translation.

This is a program that translates phrases into pig latin BTW.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:50:55+00:00Added an answer on June 12, 2026 at 6:50 am

    What you want is:

    char phrase[100];
    fgets(phrase, 100, stdin);
    

    Though, as stated in the comments and other answer, you’re using C string functions in C++ and this is very odd. You should not do so unless you are required by an assignment or something.

    Instead use:

    string input;
    getline(cin, input);
    

    To tokenize you can do the following:

    string token;
    size_t spacePos;
    ...
    while(input.size() != 0)
    {
        spacePos = input.find(" ");
        if(spacePos != npos)
        {
            token = input.substr(0, spacePos );
            input = input.substr(spacePos  + 1);
        }
        else
        {
            token = input;
            input = "";
        }
    
        // do token stuff
    }
    

    Or, to skip all of that jazz:

    string token;
    
    while(cin >> token)
    {
        // Do stuff to token
        // User exits by pressing ctrl + d, or you add something to break (like if(token == "quit") or if(token == "."))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using RhinoMocks lately but I keep running into an issue. If I
I keep running into this issue: class CCreateShortcutTask : public CTask { public: CCreateShortcutTask(
Keep running into When using the multi-mapping APIs ensure you set the splitOn param
I keep running into this design problem, and I'm not happy with my solution
I keep running into this error MemCacheError (Broken pipe): Broken pipe on my Rails
I am sure this is relatively simple, I just keep running into brick walls.
I'm writing this query and I'm running into a mental road block. I keep
I keep running into an issue where Eclipse returns No AVD's Available when trying
I'm running into a minor issue with some ASP.Net code I'm working on. For
Here's an issue I keep running into in Clojure: user=> (max [3 4 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.