I have a text file that contains the following:
6 carry OR 3 4 5
1 xor1 XOR A B
3 and2 AND A C
4 and1 AND A B
5 and3 AND B C
2 Sum XOR 1 C
each column is suppose to stand for number,name,type,input1,input2...input8
I have to be able to read a user defined text file that will then sort by number in descending order while keeping the contents of the rows together:
1 xor1 XOR A B
2 SUM XOR 1 C
...
and then I have to solve the logic circuit and display the truth table.
To start I'm just trying to get the program to read the file and print what it reads in the same format.
What I'm getting is
6
c
a
r
r
y
...
its just printing every character down in a straight line. This is my code so far
6 carry OR 3 4 5
1 xor1 XOR A B
3 and2 AND A C
4 and1 AND A B
5 and3 AND B C
2 Sum XOR 1 C
each column is suppose to stand for number,name,type,input1,input2...input8
I have to be able to read a user defined text file that will then sort by number in descending order while keeping the contents of the rows together:
1 xor1 XOR A B
2 SUM XOR 1 C
...
and then I have to solve the logic circuit and display the truth table.
To start I'm just trying to get the program to read the file and print what it reads in the same format.
What I'm getting is
6
c
a
r
r
y
...
its just printing every character down in a straight line. This is my code so far
#include "stdafx.h" #include <iostream> #include <fstream> #include <string> using namespace std; void openinfile(ifstream &infile) { char filename[100]; cout<<"Enter the file name: ";//C:\stuff\...\sample.txt depending on where your file is cin>>filename; infile.open(filename); } int main(void) { string str[10][11]; int a=0; char read; ifstream inputfile; openinfile(inputfile); if(!inputfile) { cout<<"Error: File could not be opened."<<endl; return -1; } char nextToken; char array[100]; while(inputfile>>nextToken) { array[a]=nextToken; cout<<nextToken<<endl; a++; } for(int i=0;i<a;i++) { cout<<array[i]<<endl; return 0; } system("pause"); return 0;