473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

connecting text file and functions in c++

i am trying to use the text file to use for iteration to reduce the number of points using functions.


Expand|Select|Wrap|Line Numbers
  1. #include <iostream> // library that contain basic input/output functions
  2. #include <fstream>  // library that contains file input/output functions
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.   int array_size = 1024; // define the size of character array
  8.     char * array = new char[array_size]; // allocating an array of 1kb
  9.     int position = 0; //this will be used incremently to fill characters in the array
  10.  
  11.     ifstream fin("input.txt"); //opening an input stream for file test.txt
  12.     /*checking whether file could be opened or not. If file does not exist or don't have read permissions, file
  13.   stream could not be opened.*/
  14. if(fin.is_open())
  15.     {
  16.     //file opened successfully so we are here
  17.     cout << "File Opened successfully!!!. Reading data from file into array" << endl;
  18.     //this loop run until end of file (eof) does not occur
  19.         while(!fin.eof() && position < array_size)
  20.         {
  21.             fin.get(array[position]); //reading one character from file to array
  22.             position++;
  23.         }
  24.         array[position-1] = '\0'; //placing character array terminating character
  25.  
  26.     cout << "Displaying Array..." << endl << endl;
  27.     //this loop display all the charaters in array till \0
  28.         for(int i = 0; array[i] != '\0'; i++)
  29.         {
  30.             cout << array[i];
  31.         }
  32.     }
  33.     else //file could not be opened
  34.     {
  35.         cout << "File could not be opened." << endl;
  36.     }
  37.     return 0;
  38. }
  39. // lang algorism started
  40.  public function lang(PointList[], Tolerance)
  41.   key=0
  42.   int pointList = input.txt; // use pointlist in text file used above
  43.   endP= PointList.length-1
  44.   do {
  45.     endP= PointList.length-1
  46.     if (key+1 != endP) // If there are intermediate points
  47.       line= new Line( PointList[key], PointList[endP])
  48.       /* Find the point with the furthest perpendicular distance */
  49.       maxIndex= key+1
  50.       maxD= perpendicularDistance(line, PointList[maxIndex])
  51.       for (i=maxIndex+1; i<endP; i++)
  52.         d= perpendicularDistance(line, PointList[i])
  53.         if (d > maxD)
  54.           maxIndex=i
  55.           maxD=d
  56.       if (maxD > Tolerance)
  57.         endP--;
  58.       else
  59.         for (i=key+1; i<endP; i++)
  60.           PointList.remove(i)
  61.         key= endP
  62.   } while ( endP != PointList.length-1 )
  63. end
Apr 8 '14 #1
2 1344
weaknessforcats
9,208 Expert Mod 8TB
What is it you are trying to do?

It doesn't look like the posted code will even compile.
Apr 8 '14 #2
techboy
28
you must first make a File pointer and then proceed!
Apr 14 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: adrian GREEMAN | last post by:
When I try to import a text file with new data for an existing table I get the error "1148 - the used command is not allowed with this MySQL version." I have tried with both PHPMyAdmin2.3 and...
3
by: Ron | last post by:
I have a text file with the following format (pipe delimited) |column1=value|column2=value|column3=value|column4=value|... |column1=value|column2=value|column3=value|column4=value|... I have...
3
by: kimimaro | last post by:
hi below is my save function that is used to placed data from the C program to a text file for future usage. void save() { FILE *save; int i = 0; save=fopen("employeerecord.txt", "a+");
1
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
1
by: Studlyami | last post by:
I have a text file which acts like an index to several other files. The text file contains <filename.txt>, <description for file name>. Every file listed in this index file contains data that i...
6
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
4
by: vitaminz | last post by:
Hi it's me again, I've pretty much finished a program I'm making, which does the following: The program is for a garage, and it does the following functions: Adds a new car Display cars Amend...
15
by: davidleeis14 | last post by:
I have been given and assignment to complete which is about a savings club. The club has two member types (Full and Young). I have written a abstact (Member) class with virtual functions and two...
3
zmbd
by: zmbd | last post by:
It seems that in VBA some the most fundamentally basic commands for file control are the hardest to find any information for, for example, the basic File operation commands, such as DIR(), CHDRIVE(),...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.