I have a problem, Im reading numbers from a text file like this
10 20 3
x1 y1
x2 y2
and so on, x and y are values and theres no limit but will probably not be more than 5 or so.
What I want to do is fill an array with 10 at the first spot, 20 at the second spot, 3 at the third spot, and so on and disgregard the white spaces and new lines since im reading one character at a time. (not sure of a better way to do this)
I can open the file and get the characters from it and thats it.
10 20 3
x1 y1
x2 y2
and so on, x and y are values and theres no limit but will probably not be more than 5 or so.
What I want to do is fill an array with 10 at the first spot, 20 at the second spot, 3 at the third spot, and so on and disgregard the white spaces and new lines since im reading one character at a time. (not sure of a better way to do this)
I can open the file and get the characters from it and thats it.
Code:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <stdio.h>
using namespace std;
void main()
{
char ch;
char z;
char filename[30];
char fileinfo[100];
cout<<"what is the name of the file? "<<endl;
cin>> filename;
FILE *inFile = fopen(filename, "r");
if (!inFile)
{
printf("Cannot find the file\n");
}
while ((ch = fgetc(inFile)) != EOF)
------------------
while ((ch != '\n' || ch != ' ' ) //I know this line is bad
{
for (int i = 1; i < 100; i ++) //this is my touble area
{
fileinfo[i] = ch;
}
}
--------------------------
cout << fileinfo;
fclose(inFile);
cout << endl;
cin >> z; //here so command prompt doesn't close
}
Comment