Win a copy of Head First Android this week in the Android forum!

James Stanford

Greenhorn
+ Follow
since Mar 01, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Stanford

I kinda know java, in fact I knew the line you translated, my problem is that I don't have much experiance with java and I keep getting stuck at every little syntax error and don't know what to do. I guess I'll try mostly translating it and then get help w/ it.
All right here we go.

here is an example of what I'm trying to read:
GA
D
A
Goal
L
A2
A1
A4
Z
ZA
Ezea
How would you read in these words into an array specifided by the command line in java?
[ April 07, 2003: Message edited by: James Stanford ]
[ April 07, 2003: Message edited by: James Stanford ]
18 years ago
I'm not very good at writting in java so I wrote this code in c++. but now I need to convert it into java. Can someone help me do this?

[code]
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[]){
if (argc !=2){
cerr << endl << "Error: syntax for command should be: " << argv[0] << " filename\n\n";
exit(1);
}
int i = 0, elements = 0;
char *ch;
char *buffer[13];

// Open file specified by argument one
ifstream fin(argv[1], ios::in);
if (!fin || fin.bad() || fin.eof() ){
cerr << endl << "Error: file not found\n\n" ;
exit(1);
}

// Get file size
cout << "Attempting to read file length... ";
fin.seekg(0,ios::end);
i = fin.tellg();
fin.seekg(0);

// Allocate memory for file content
ch = new char [i];
// read contents of infile into buffer
while(!fin.eof()){
fin.getline(ch, i);
buffer[elements] = ch;
cout<< "ch [" << elements << "]:" << ch << endl;
cout<< "buffer [" << elements << "]:" << buffer[elements] << endl;
elements++;
}
cout << "\nNumber of elements in file: " << elements << "\n";
// display file contents
for (i = 0; i < elements; i++)
cout << "Element [" << i << "]: " << buffer[i] << endl;
delete[] ch;
cout << "\nData read succesfully.\n\n" ;
fin.close();
return 0;
}
[\code]
18 years ago
Yes thanks thats what I was looking for.
This is what I did to it but I'm getting compiler errors:

After I create I get to figure out how to put this info into a minimum hieght binary tree
I'll be having fun...hmmmm
[ March 01, 2003: Message edited by: James Stanford ]
18 years ago
I'm trying to read in words from a file and then put those words into and array and sort the array, I kinda have a program but it isn't working can some one help me out with it, It would be nice to see some source code. I'm new to java and am having problems with the syntax and object orintation of the language. Anyways some help would be nice
18 years ago