473,898 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to create aan array from a text file

1 New Member
Hi

I am trying to build an array out of an input text file as shown below.

pattern1
SAF 10 1 10
CLB 20 18 10 11

pattern2
SAF 20 1 10 11
SAF 30 1 10
SAF 40 1 11
SAF 10 0 10
SAF 11 0 11

pattern3
SAF 31 1 10
SAF 21 1 11
SAF 10 0 10
SAF 11 0 11

pattern4
SAF 10 1 10
CLB 20 18 10
SAF 21 1 11
SAF 11 0 11

now here the first 3 fields in each line constitute the value field (like value1).Now suppose under heading one there is some value for value1 then it needs to go in the first column. Same way if heading4 has a value for value1 it needs to go under corresponding column4. So the output array should generated would be something like this

[CLB 20 18] [10 11] [ NULL] [ NULL] [ 10]
[SAF 10 0] [ NULL ] [ 10 ] [10 ] [NULL ]
[SAF 10 1 ] [10 ] [NULL ] [ NULL ] [10 ]
[SAF 11 0 ] [NULL ] [11 ] [11] [ 11 ]
[SAF 20 1 ] [NULL ] [10 11 ] [NULL ] [NULL ]
[SAF 21 1 ] [NULL ] [NULL ] [11 ] [11 ]
[SAF 30 1 ] [NULL ] [10 ] [ NULL ] [ NULL ]
[ SAF 31 1 ] [NULL ] [ NULL ] [10 ] [NULL ]
[ SAF 40 1 ] [NULL ] [11 ] [ NULL] [ NULL ]

The square brackets are just to show the whole thing as one string

Now if I read the complete line using getline then I am not able to ignore the lines with word pattern. If I use cin then I get each word individually. I hope I am not making it too complicated. My code so far is:

#include<iostre am>
#include<string >
#include <fstream>
using namespace std;

int main(){
ifstream input("detectio n_report.txt", ios::in);
int columns = 0;

if(!input)
{
cerr<<"File could not be opend\n";
exit(1);
}

string value;
while(getline(i nput,value)){

string check = value.substr(0, 1);
if (check == "p")
{
columns = columns + 1;
}
else{

//Here I want to read the lines without the "pattern" words.
//Secondly I just want to read only the first three groups to put in an array.
//which is quite difficult using a substr as some will need 8 characters and some will need 9.
}
cout << value << "\n";
}

input.close();
cout << "Columns: " << columns <<"\n";

return 0;
}
Nov 16 '06 #1
0 1208

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

Similar topics

8
2282
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in each row needs a <textarea> control. The background supporting classes are completed, the only task left now is to create the web page. I am at a loss on how to create the table in the page populated by the data. Previously, I would have just...
2
3850
by: monkeyinquisition | last post by:
Hi All, I'm trying to read data from a text file into an array. The text file (a test) looks like this: 1 2 3 4 5 6 7 8
16
3266
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will not print in the username or email amddress of the person doing the download - which I am collecting from a form on the previous page. I can get the name and email address to print out normally, just not into the email sending body. I have...
23
7446
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
4
5676
by: | last post by:
Hi all, I want to create a method that does the following: 1) Programmatically instantiate a new XmlDataSource control 2) For each file in a named directory, make a "FileSystemItem" element 3) On each FileSystemItem Element, make two child nodes, one with the file name, one with the file size. ie. <filesystemitems> <filesystemitem>
4
8291
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
1
4035
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
3
4242
by: gsuns82 | last post by:
HI all, I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file. For an instance: test.html: -------------- <html> <head> <script>
7
16181
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under the domain name www.blog-start.com Unfortuantely it is not not working correctly
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10854
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10480
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9658
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
4295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3303
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.