×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# problem opening files based on position...

## problem opening files based on position...

(OP)
I have a program that is supposed to open a file based on the coordinate on an x, y, and z coordinate.  It then gets information about that coordinate and outputs it.  But for some reason it does not work correctly.. So I took away the Z axis to make it easier to work with, and then I deformed some of the code to try to find the bug, but i cannot.  Maybe someone could help me if they looked at it, so here is the defective code... Please help  :

do
{
acc = 1;
cin >> dir;
strcpy(dirtest, "n");
strcpy(dirtest1, "ne");
strcpy(dirtest2, "e");
strcpy(dirtest3, "se");
strcpy(dirtest4, "s");
strcpy(dirtest5, "sw");
strcpy(dirtest6, "w");
strcpy(dirtest7, "nw");
strcpy(dirtest8, "d");
strcpy(dirtest9, "u");
if (strcmpi(dir, dirtest) == 1)
{
y++;
y1 = 1;
}
else if (strcmpi(dir, dirtest1) == 1)
{
y++;
y1 = 1;
x++;
x1 = 1;
}
else if (strcmpi(dir, dirtest2) == 1)
{
x++;
x1 = 1;
}
else if (strcmpi(dir, dirtest3) == 1)
{
y--;
y1 = -1;
x++;
x1 = 1;
}
else if (strcmpi(dir, dirtest4) == 1)
{
y--;
y1 = -1;
}
else if (strcmpi(dir, dirtest5) == 1)
{
y--;
y1 = -1;
x--;
y1 = -1;
}
else if (strcmpi(dir, dirtest6) == 1)
{
x--;
x1 = -1;
}
else if (strcmpi(dir, dirtest7) == 1)
{
y++;
y1 = 1;
x--;
x1 = -1;
}
else if (strcmpi(dir, dirtest8) == 1)
{
z--;
}
else if (strcmpi(dir, dirtest9) == 1)
{
z++;
}
else
{
acc = 0;
}
do {
if (acc == 0)
{
break;
}
if(x < 10 )
{
strcat(town, "00");
}
else if(x > 9 && x < 100)
{
strcat(town, "0");
}
sprintf(town1, "%d", x);
strcat(town, town1);
if(y < 10 )
{
strcat(town, "00");
}
else if(y > 9 && y < 100)
{
strcat(town, "0");
}
sprintf(town2, "%d", y);
strcat(town, town2);

strcat(town, "000");
// sprintf(town3, "%d", z);
// strcat(town, town3);
strcat(town, ".dat");
ifstream infile(town);

acc = 1;
infile >> roomdesc;
cout << roomdesc << endl;
infile.close();
}
while (strcmpi(dir, "exit") != 1);
}
while (strcmpi(dir, "exit") != 1);

### RE: problem opening files based on position...

What exactly is it not doing right?

James P. Cottingham

International Veneer Co., Inc.
All opinions are mine alone and do not necessarily reflect those of my employer.

### RE: problem opening files based on position...

(OP)
nevermind.. i fixed it..

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!