|
right.. so i added this:
#include codigo.txt (with the rectangular brackets)
but it gives me this error: "dll.cpp:8:22: codigo.txt: No such file or directory"
i put the file in the possible directories (im using MinGW) I:\Programas\MinGWStudio\Templates\dll\Debug and I:\Programas\MinGWStudio\Templates\dll (because i dont know where its suppose to be..
-- modified at 3:20 Monday 4th June, 2007
|
|
|
|
|
GatoFedorento47 wrote: right.. so i added this:
#include codigo.txt
He meant to modify your post so that the angle brackets did not get "eaten." Modifying your code is obviously going to cause problems.
Notice the two angle brackets that are above the smileys.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
#include<windows.h>
#include<<stdio.h>
#include<<stdlib.h>
#include<<stdio.h>
#include<<time.h>
#include<<fstream>
#include<string>
#include <codigo.txt>
int="" escolha_cod(double="" saldo,int="" escolha)
{
="" file="" *codigo;
int="" i="0,linha=0,j=0,aux=0;
char" vec[2];
using="" namespace="" std;
string="" line;
="" ifstream="" myfile="" ("codigo.txt");
if="" (myfile.is_open())
{return="" 47;
="" for(i="0;i<10;i++)
" {=""
="" getline(myfile,line);
=""
="" const="" char="" *c_line;
="" strncpy(vec,line.c_str(),3);
="" aux="atoi(&vec[0]);
" if(aux="=escolha)
" {linha="i;
" }
myfile.close();
}
return="" 47;
}
int="" main()
{int="" var;
var="escolha_cod(10,12);
printf("%d",var);
getchar();
return" 0;}
apparently="" the="" problem="" is="" with="" <code="">if (myfile.is_open()), so i just wanted to know how do you open files.. :s
|
|
|
|
|
Is this supposed to be an improvement? Paste your code into a reply, highlight the code, and click the "pre" formatting button (above the smileys). Now for the important part: click the Preview button. If anything is askew, fix it. If any angle brackets are missing, delete the left angle bracket and then click the '<' above the smileys.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<fstream>
#include<string>
#include<codigo.txt>
int escolha_cod(double saldo,int escolha)
{
int i=0,linha=0,j=0,aux=0;
char vec[2];
using namespace std;
string line;
ifstream myfile ("codigo.txt");
if (myfile.is_open())
{
for(i=0;i<10;i++)
{
getline(myfile,line);
const char *c_line;
strncpy(vec,line.c_str(),3);
aux=atoi(&vec[0]);
if(aux==escolha)
{linha=i;
i=10;}
}
myfile.close();
}return 47;
}
int main()
{int var;
var=escolha_cod(10,12);
printf("%d",var);
getchar();
return 0;}
sorry! its the first time im writing here.. i think now is just the way u asked..
|
|
|
|
|
GatoFedorento47 wrote: sorry! its the first time im writing here..
No problem. Everyone's got to start somewhere.
GatoFedorento47 wrote: i think now is just the way u asked..
Yep. All you got to do now is fix the problem.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
that's why im posting here.. so anyone can give me ideias on how to put this right.
|
|
|
|
|
GatoFedorento47 wrote: so anyone can give me ideias on how to put this right.
I already gave you the solution here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
GatoFedorento47 wrote: strncpy(vec,line.c_str(),3);
This is guaranteed to fail. The variable vec can only hold only character plus the '\0' terminator.
GatoFedorento47 wrote: aux=atoi(&vec[0]);
Is the same as:
aux = atoi(vec); escolha_cod() returns nothing but 47. Is this intentional?
GatoFedorento47 wrote: ifstream myfile ("codigo.txt");
Shouldn't you be specifiying a path with this?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
for the two first problems, i still have to search in the net, but about escolha_cod() returning 47 was intentionla because in the function i've been moving it around to see where the function was failing. and it's after:
if (myfile.is_open()){
So most probably this is the error, but i dont understand, everybody uses it! and its not working 4 me
|
|
|
|
|
GatoFedorento47 wrote: ...but i dont understand...
The likely cause is the aforementioned call to strncpy() , which is stepping over part of the return value on the stack.
GatoFedorento47 wrote: ...everybody uses it!
But not in it's current form.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: The likely cause is the aforementioned call to strncpy(), which is stepping over part of the return value on the stack.
allright.. im not english as U might guessed by now, so i dont really understand "aforementioned". searched in the net and its "the previous" ? but strncpy( ) is called after if (myfile.is_open()) . i believe the function cant get access to the file in question because if i put the return after this piece of code it gives me something completely different from 47 :s anyway, if the error is indeed what u'r saying could you explain it for "dummies" pls
|
|
|
|
|
GatoFedorento47 wrote: i believe the function cant get access to the file in question because if i put the return after this piece of code it gives me something completely different from 47
So what you are saying is that you have this:
int escolha_cod(double saldo,int escolha)
{
FILE *codigo;
int i=0,linha=0,j=0,aux=0;
char vec[2];
using namespace std;
string line;
ifstream myfile ("codigo.txt");
if (myfile.is_open())
return 47;
{
for(i=0;i<10;i++)
{
getline(myfile,line);
const char *c_line;
strncpy(vec,line.c_str(),3);
aux=atoi(&vec[0]);
if(aux==escolha)
{
linha=i;
i=10;
}
}
myfile.close();
}
return 47;
} Is that right?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
if (myfile.is_open())<br />
{return 47;
... like this lol
|
|
|
|
|
GatoFedorento47 wrote: myfile.is_open())
Ok, so is the myfile.is_open() statement evaluating to zero or a non-zero value? In other words, which of the two return statements is being executed?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
ok.. i dont know what i did, but now is working! lol .. now that that is working i copied to visual studio (where im building my dll) and compiled. everythings fine, but when i run my actual program made in VB when i call the function it keeps returning 0 again arghhh i hate this stupid things..
|
|
|
|
|
GatoFedorento47 wrote: ...but now is working!
Not if you haven't increased the size of the vec variable.
GatoFedorento47 wrote: ...but when i run my actual program made in VB when i call the function it keeps returning 0 again
I suspect it is a relative .vs absolute path issue.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: I suspect it is a relative .vs absolute path issue.
sorry.. didn.t understand, what do you mean? that VB doesn't know where is the file?
|
|
|
|
|
GatoFedorento47 wrote: didn.t understand, what do you mean?
See here.
GatoFedorento47 wrote: that VB doesn't know where is the file?
Exactly. Set a breakpoint in your DLL on the is_open() statement to verify.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
yes, the problem was that the file wasn't in the place it should be. lol. what i did was: instead of reading, i put write and by default, if the file doesn't exist, it creates one. after running the program, i just searched through windows search and found that test file. that way i knew where to put my original txts thks for all the help [[]]
|
|
|
|
|
I asked you if the path could be part of the problem here. By not specifiying a complete path to the file, your code will still continue to fail under certain circumstances. It's better to tell the OS where to create the file, rather than have the OS tell you where the file will be created (today).
If you are interested in a more C++ solution, rather than the C solution, try:
int escolha_cod( double balance, int choice )
{
std::ifstream myfile("c:\\codigo.txt");
std::vector<int> numbers;
std::copy(std::istream_iterator<int>(myfile), std::istream_iterator<int>(), std::back_inserter(numbers));
myfile.close();
std::vector<int>::iterator it = std::find(numbers.begin(), numbers.end(), choice);
int ret = -1;
if (it != numbers.end())
ret = (int) (it - numbers.begin()) + 1;
return ret;
}
void main( void )
{
int var = escolha_cod(10.0, 1500);
printf("%d",var);
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
ur right, but either way is working now, so.. thks again
|
|
|
|
|
Did you ever get this straightened out?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
i am trying to step through my simple application. But its so annoying in MFC. Well when i use F10 or F11 it goes directly to appmodul.h and run the whole application frm there. Now if i put break pt. and press F5 and the step through it. It would start going to so many MFC lib source files and after going through 5-6 header files it gives error that no source found...
I really dont want to step through or step into the mfc inbuild source files. I want to only step through my written code. How can i achieve this. There must be some way out. Its so hard to debug like this.
Any help would be appreciated.
Thanks
|
|
|
|
|
Don't step in, just step over. Stepping in will go into MFC, this is a *feature*, I wish I could do that in C#, the best I can do is read the source via reflection. But, you can just step over, or if you find yourself in MFC code, step out.
worst comes to worst, set a breakpoint where you next want to stop and hit 'continue'.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|