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 4265500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:37:57+00:00 2026-05-21T06:37:57+00:00

I’m a bit new to programming so the answer to my problem has not

  • 0

I’m a bit new to programming so the answer to my problem has not become obvious, although I have tried to accomplish the task a number of ways.

The issue is that I’m trying to take an array of words, remove any punctuation from the array, and place the new words into a separate array. I attempted to do this but I keep getting garbage values when I output the new array.

The code reads:

norm(sepwords1,sepwords2,numwords);      <- where I called it in main

void norm(string words[], string wordz[],int count)       
{

        int i;
        int x;
       
        string newstring="";
        char current;
       
         
    for(i=0; i<count; i++)
        {
        for(x=0; x<words[i].length();x++)
        {        
          current= words[i].at(x);
                if(ispunct(current)==0)
                {
                newstring += current;
                }
        
        }        
                wordz[i]= newstring;
        }
 
}

the full main function is:

int main (int argc, char* argv[])
{



int count = argc;
int i;
string filename[count];
ifstream infile;
string fromfile[1000];
int numdata;
int pass;
char current;
int sum;
string masterstring="";
int x;
string sepwords[2000];
int sum1;
string temp="";
int start;
int fin;
string newstring="";
string newfile[1000];
int place;
int numwords;
string sepwords1[2000];
string newmaster="";
int j=0;
string currentz;
string highmark;
int index[2000];
string sepwords2[2000];
int counta=0;

for(i=0; i < count-1; i++) 
{
filename[i] = argv[i+1];
}

for( i=0; i < count-1; i++)
    {
    infile.open(filename[i].c_str());
    
    numdata=0;  
    
    while(!infile.eof())
    {
    
    getline(infile, fromfile[numdata], '\n');
    numdata++;
    
    }


    
    

    for(i=0; i<numdata; i++)
    {
    cout<<fromfile[i]<<endl;
    masterstring += fromfile[i] + " ";                                      //NUMBER ONE
    }

    

    numwords = split(masterstring, sepwords);
    cout<<numwords<<endl;                                                       //NUMBER TWO


    }

    for(i=0;i<numwords;i++)
    {
        newstring = toupper(sepwords[i].at(0));         
        newstring += sepwords[i].substr(1);
        sepwords1[i] = newstring;
        newstring="";
    }
    
    for(i=0;i<numwords;i++)
    {
    
    
    newmaster += sepwords1[i] + " ";
       j++;
          if(j > 10)
          {
           newmaster+= '\n';
           j=0;
          }

    }
    cout<<newmaster<<endl;                                              //NUMBER THREE



    norm(sepwords1,sepwords2,numwords);
    
        for(i=0;i<numwords;i++)
    {
    cout<<sepwords2<<endl;
    }

return 0;
}
  • 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-05-21T06:37:58+00:00Added an answer on May 21, 2026 at 6:37 am

    Not sure what you mean by gargage output?

    If I call your function with this (g++ 4.4.5)

    #include <string>
    #include <iostream>
    using namespace std;
    int
    main  (int ac, char **av)
    {
      int numwords = 3;
      string sepwords1[] = {"one,", "two", "three"};
      string sepwords2[numwords];
      norm(sepwords1,sepwords2,numwords);  
      for(size_t i=0;i<numwords;++i){
        std::cout<<"sepwords2["<<i<<"] = "<<sepwords2[i]<<std::endl;
      }
    
    }
    

    then I get the output

    sepwords2[0] = one
    sepwords2[1] = onetwo
    sepwords2[2] = onetwothree
    

    Is this not what you want?

    If you don’t want concatination, then you need to reset the newword variable,

      wordz[i]= newstring;  //this is in your norm function 
      newstring="";         //this is the line I added. 
    

    then the output is

    sepwords2[0] = one
    sepwords2[1] = two
    sepwords2[2] = three
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace

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.