473,325 Members | 2,828 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,325 software developers and data experts.

Reading a file into an INT array?

Steel546
So I'm trying to read a file into an INT array with no luck. I don't want to use a char array because I'm actually performing math operations. Any help would be GREATLY appreciated. I'll post the section I need.

And I know there's some conversion warnings, but those are the least of my worries. The text file is simply numbers with spaces, example:

37 181 201 89 64


Expand|Select|Wrap|Line Numbers
  1. int decrypt() {
  2.  
  3.         ifstream in("encrypt.txt");
  4.  
  5.         // Test to see if the file will open.
  6.         if(!in){
  7.             cout << "Cannot open file.";
  8.                         return 1;
  9.         } //end if
  10.  
  11.         int arr1[160];
  12.         int count1=1;
  13.  
  14.         for(int g=0; g<count1; g++){  // Not sure what to do here?
  15.             in.getline(arr1[g], ' ');
  16.         }
  17.  
  18.         in.close();
  19.  
  20.         for(int k1 = 0; k1 < count1; k1++){
  21.  
  22.             double m, m1;
  23.             m = arr1[k1];
  24.             m1 = pow (m,d);
  25.             double m2 =  fmod(m1,n);
  26.             arr1[k1] = m2;
  27.             //cout << a[k] << endl;
  28.         } //end for
  29.  
  30.         for(int ij=0; ij < count1; ij++){
  31.             cout << arr1[ij] << " ";
  32.         }
  33.  
  34.  
  35.     }; //end decrypt
Apr 18 '11 #1
2 2199
whodgson
542 512MB
a little research suggests that fscanf()may be a better bet than in.getline()
Apr 19 '11 #2
It's alright, I guess I can close this. I had to write some TCP socket layer stuff in Java, so I just completely re-wrote everything in Java (nightmare).

Thanks for the suggestion, I'll look into that the next time.
Apr 19 '11 #3

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

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
12
by: Eigenvector | last post by:
I've been dinking around with this code for a while now and I can't seem to figure out where the problem lies. The original problem was that I for some reason or another couldn't allocate few...
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...
15
by: Shuch | last post by:
Hi all, i m trying to read from a file and then copy it into an array...my code is as follow..it runs fine but i cant understand y it doesnt show me any output?? here is my code... using...
1
by: sreedivya | last post by:
hi all how to declare and reading an array values in sql server thanks in advance
3
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I'm trying to write an array of structures named myStructArray to a binary file and later on read it back. Although I could complete the entire project in C in about 2 minutes, I...
1
Coldfire
by: Coldfire | last post by:
Hi, The strange problem i am having is, the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file. The code is...
1
by: bjoarn | last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++. Dll reports back to the the C# programm throug...
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...
1
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.