473,322 Members | 1,610 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,322 software developers and data experts.

Reading a file.. trying to exclude some character

Hi,

Trying to read an input file, of characters with spaces and carriage
returns. Basically it is a 20x20 matrix of characters with spaces. I
want to load the information into an two dimensional array.

Cannot seem to figure out how to do like if the read character equals a
space or carriage return, don't put it in the array.

Any ideas?

Thanks,

RishiD

ifstream fin;

string fileName = "sample";

char c;

// Open the file associated with stream fin
fin.open(fileName.c_str());

int x = 0, y = 0;
while (fin.get(c))
{
if (x == 20)
{
x = 0;
y++;
}
// if c != space or crlf ( i know the code below is completely
wrong, just trying to show what i want
if (c != " " || c != "\n")
{ dictArray[x][y] = c;
x++;
}
}

Nov 30 '06 #1
1 2259
RishiD wrote:
Hi,

Trying to read an input file, of characters with spaces and carriage
returns. Basically it is a 20x20 matrix of characters with spaces. I
want to load the information into an two dimensional array.

Cannot seem to figure out how to do like if the read character equals a
space or carriage return, don't put it in the array.

Any ideas?

Thanks,

RishiD

ifstream fin;

string fileName = "sample";

char c;

// Open the file associated with stream fin
fin.open(fileName.c_str());

int x = 0, y = 0;
while (fin.get(c))
{
if (x == 20)
{
x = 0;
y++;
}
// if c != space or crlf ( i know the code below is completely
wrong, just trying to show what i want
if (c != " " || c != "\n")
First, use && not ||. The above comparison (once it's made well formed
-- see second point) will always compare true. A character is always
(not blank or not newline).

Second, compare against chars (' ', '\n'), not against string literals.
{ dictArray[x][y] = c;
x++;
}
}
Nov 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
1
by: utab | last post by:
Hi there I am trying to read from a file, I am trying to read certain fields,there are 6 fields in this file like --------/--------/--------/--------/--------/--------/ All fields are 8...
1
by: Andrea Gavana | last post by:
Hello NG, that may sound a silly question, but I didn't find anything really clear about the issue of reading unformatted big endian files with Python. What I was doing till now, was using...
2
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
9
by: Amkcoder | last post by:
I am trying to read a file a character at a time, I want to read in the new line character. I am printing out each character to the screen. For some reason it will not print out the new line. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.