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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:53:03+00:00 2026-06-02T06:53:03+00:00

I am reading from a file and passing the front of the array(pointer) back

  • 0

I am reading from a file and passing the front of the array(pointer) back into my main function. The problem I am having is that it is not copying the blank spaces in between the words. For example Hello Hello comes out as HelloHello.

I started by using getLine instead and ran into the problems of size of the file. I set it to 500 because no files will be larger than 500, however most files will be below 500 and I am trying to get the exact size of the file.

Here is my code:

char infile()
{
   const int SIZE=500;
   char input[SIZE];
   char fromFile; 
   int i=0;

   ifstream readFile;
   readFile .open("text.txt");
   while(readFile>>fromFile)
   {
     input[i]=fromFile;
     i++;
   }
   cout<<endl;
   returnArray=new char[i];//memory leak need to solve later
   for(int j=0;j<i;j++)
   {
      returnArray[j]=input[j];
      cout<<returnArray[j];
    }
    cout<<endl;
  }
  return returnArray[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-06-02T06:53:04+00:00Added an answer on June 2, 2026 at 6:53 am

    Depending on what your file format is, you may want to use ifstream::read() or ifstream::getline() instead.

    operator >> will attempt to ‘tokenize’ or ‘parse’ the data stream as it is being read, using whitespace as separators between tokens. You’re interested in getting the raw data from the file with whitespace intact, therefore you should avoid using it. If you want to read data in one line at a time, using linefeeds as separators, you should use getline(). Otherwise use read().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble reading data from a file into a vector of Orders.
I'm trying to convert a string that I'm reading from a file to lowercase
I am reading data from a file that has, unfortunately, two types of character
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
I'm reading a file(a flash swf) from .Net 3.5 that has a header which
I am reading records from file and inserting into database. I am using DB2
I've written a simple library file with a function for reading lines from a
Why does reading from __DATA__ work and reading from the file doesn't (Loose unescaped
In order to improve performance reading from a file, I'm trying to read the
I'm Using FILE * F opened in _sfopen () I'm reading from the file

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.