View Single Post
Old 03-02-2005, 12:25 AM   #1 (permalink)
letsC
Registered User
 
Join Date: Mar 2005
Posts: 4
letsC is on a distinguished road
Text file input to an array

Hello,

I'm relatively new to C++ and trying to read a text file and store the lines of the text file in to an array. Each line in the text file is 0x.... format input representing bits. The following code is part of larger program. When I run the exe, it simply hangs. If I use the cin method of inputting in the array, it works.

int a[100];

ifstream infile("in.txt");

while (! infile.eof())
{ infile>>hex>>a[i];
i++;
}

Also in the same program,
SOURCEIP_STR = SOURCEIP_OCT1 + SOURCEIP_OCT2 + SOURCEIP_OCT2 + SOURCEIP_OCT3 + SOURCEIP_OCT4;
gives me errors that "cannot add two pointers".

All the variables above are type integers. SOURCEIP_OCT1 and other variables are derived from performing bitwise shifts on the elements of a[i].
I'm doing something wrong here. Do I have to use character strings? Is it possible to read the contents of the text file into a character array? How would I do that? I've referred to some sources but I'm confused on what to do here. The whole program is on IP packet fragmentation and re-assembly.
Help would be greatly appreciated!
letsC is offline   Reply With Quote