First step would be to learn the difference between = and == when comparing stuff.
scru commented: looks like you beat me to this one +3
First step would be to learn the difference between = and == when comparing stuff.
> but don't want to reinvent realloc just because it doesn't work on <reallyoldcompiler>.
Care to post an example of that which "doesn't work".
Because realloc is a tricky function, and odds are that it's your code that screwed up.
Oh, and there's absolutely no guarantee that the memory will (or won't) move on every single call, whether you're making it bigger, smaller or the same size.
Some debug versions move it all the time just to make sure the caller is being honest.
Sure, but you're going to have to write quite a lot of software to do it.
What's your definition of "simple"?
Or put it another way, what have you been studying for the past few weeks or months, and how much attention were you paying?
Sure, there are plenty of people here who can help with that.
> what does in ncurses does?
What do hyperlinks and web search engines do?
> i'm more into java so i'm thinking that it is similar to java's AWT and SWING library. am i right?
Right, which is why you mentioned a terminal (aka, basic character based I/O) to begin with.
If you want that kind of interface, consider wxWidgets
Note that this isn't a link, can you still manage?
Apart from removing
using namespace std;
from the header file (that's a really bad idea), what do you want?
It seems fairly simple as it is.
Perhaps consider a .cpp file to go with that .h, and put all the implementation code into the .cpp file?
Consider instead...
- using opendir() to open a directory
- using readdir() in a loop to get each directory entry
-- using stat() on each entry to get the permissions
-- evaluate those permissions as you want
- using closedir() when you're done.
Use a while loop instead of goto start.
Do a web search for "CSV file format".
It's a nice simple text-only format file which is very easy to create, and which excel can readily import.
http://en.wikipedia.org/wiki/Central_Board_of_Secondary_Education
Ah yes, the bunch of xxxxx who insist on teaching "c" using a compiler which became obsolete a full 20 YEARS ago. It's not like there's a shortage of high quality, free and most importantly up to date compilers to choose from.
This is why I don't worry about out-sourcing. The entire continent is full of programmers with skills so far out of date with the modern world as to be useless.
Lets see.
If this is a C++ program, where are the classes?
Why so many global variables?
Why so many variables with short meaningless names?
Why do so few functions have parameters?
Why are functions like display1() display2() totally meaningless descriptions of their function?
Why the chaotic mix of cout and cprintf?
Why is code for say inputting a traveller name duplicated (and not a function)
Why is the penalty for incorrect input so harsh (being dumped out of the program)?
Maybe get a compiler which is compatible with your OS?
Basically, you've been lucky up until now that your fossil compiler worked at all on your shiny new OS. Now that you've discovered there are limits, either learn to live with them or move on up into the real world.
http://www.catb.org/~esr/faqs/smart-questions.html#bespecific
Better swing by this one a few more times, until you get it
http://www.daniweb.com/forums/announcement8-3.html
There doesn't seem to be anything wrong, so it's most likely somewhere else in your code.
You could try breakpoint in the dtor, and check that _number_of_dev is what you expect. Oh, and by the way, names beginning with _ are reserved (with few exceptions).
Memory corruption problems have a "cause" and an "effect", which can be separated in the code by a long way (in time, and in location in the code). Looking at where it crashes is seldom that informative. For example, if you try this code (and ONLY this code) in a standalone program, it'll probably work. If it does work, it's a pretty solid indication that the problem is elsewhere.
Since you seem to be on Linux, then I suggest
g++ prog.cpp -lefence
gdb a.out
run
Electric fence is a memory diagnostic library which will trap on the instruction which corrupts memory (and drop you in the debugger). As opposed to your present situation of where the code notices there is a problem and drops you back to the shell.
Your question is neither interesting, nor urgent.
Just your run of the mill student homework, of which many examples can be found around these parts.
http://www.catb.org/~esr/faqs/smart-questions.html#homework
http://www.catb.org/~esr/faqs/smart-questions.html#urgent
And while we're at it, you tripped over this in your rush to post
http://www.daniweb.com/forums/announcement9-2.html
Set your app to listen to 127.0.0.1:888
Your filter then connects to 127.0.0.1:888 and itself listens on port 888 of the machine itself.
Your filter now sees all the traffic on that port, and can forward/modify/drop as necessary.
So keep reading and figure out how to make a function out of it then.
Maybe the "find" command with the "exec" option?
Spend a few weeks practicing with ncurses and drawning text windows, typing in one and echoing responses in the other.
Spend a few more weeks practicing network programming with beej to the point where you can send and receive messages (to yourself).
Then you might have a go at bringing the two ideas together.
Well you do use eof() in a control loop, which is bad
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351
eof() is a state (the result of a past failure), not a prediction (of a future failure).
That is, if you have a 10 char file and read 10 chars, then eof() will NOT be true. It's only when you try to read (and fail) to read the 11th char that eof() will become true.
The corrollary of all this is that ALL your file read functions should check their return result to see that they succeeded.
Or you could just post some actual code....
So did you do ANY research on how to write a function in shell?
Did you try a few examples to see how it might work for you?
Put the thing in quotes
1,"hello, world",2
would be 3 columns.
Use excel to save a simple csv format file with a field containing a comma.
> which is usually at the lower part of the memory to prevent stack overflow from overwriting it.
And where stacks grow downwards, that would be a problem right?
C doesn't actually require a "stack", only some memory which exhibits the property of allowing scoping. Since many machines have a conveniently large stack space, this is a convenient choice. But there are some machines where the native call stack is tiny, and another approach is required.
Also, the relative positions of the memory types is completely implementation defined, as is the direction in which the stack grows (if it has a stack at all).
You don't reset fac to 1 each time around.
If you print it out, you'll see.
Isn't that just gcd(a,gcd(b,c))
> So please write a program to find the GCD of 3 numbers.
No, we suggest, you do it.
My suggestion is you look to see if your shell supports functions, which you can call in the manner I've described.
If you're talking about something like VGA, yes.
There's a block of memory which more or less equates to pixels on screen.
No - CPUs know nothing about ASCII.
Nor do CPU's have "built-in" functions for anything, unless you count "multiply" as a built-in function.
Nor are they capable of "drawing" anything.
Neither do operating systems.
> drink her pretty
Just how much drink was drunk in that last picture? :twisted:
> is this loop tends to infinity for any value of i and j
Like any pair of positive numbers?
Why are you trying to do maths in the shell (which it really isn't set up to do).
> .i know i should make a loop inside but im very weak in programming
You'd better be a demon cryptographer then.
Without one or the other, this seems a hard problem.
Just call mul several times in a row.
First you need to decide which function is supposed to be reading the file.
> You should be checking for mem leaks as you write the code, not at the end
Agreed, and add lint to the list as well.
To add to what skatamatic skatamatic said.
The leak report also prints out a {nnnnn} number, which is the number of the block allocated. There is a variable in crtdbg.h which you can set to this number the next time you run the program (in the debugger).
When that block is allocated, it will trap into the debugger to give you a nice opportunity to look around at who is allocating it, and therefor who should be freeing it later.
It's that Y2K feeling all over again.
http://news.bbc.co.uk/1/hi/business/7660409.stm
Personally, I think one extra digit is a little optimistic.
Dunno.
But comparing "i want to design a new web browser" with the cast of thousands (probably) who work on firefox, what exactly are you hoping to achieve?
Firefox it seems uses many languages, as no single language would be the best choice at all levels of the program.
Why does search need to open the file (again)?
It doesn't use it (nor does it close it).
To avoid the double fgets(), you need to apply the same technique to main() as well (the scanf call).
Another question is which OS is in between you and the hardware.
You need to go digging through MSDN to find the equivalent (or at least work-alike) API for the platform you're using.
> if (((ptr + i)->UName) == search_val)
1. You can simplify the pointer notation to ptr[i].UName
(just like if you were accessing the original array in main
2. Use strcmp to compare strings, like if ( strcmp( ptr[i].UName,search_val) == 0 )
You're also mixing fgets and fscanf, which will lead to surprises.
char buff[BUFSIZ];
fgets( buff, BUFSIZ, stdin );
sscanf( buff, "%s", ptr[*count].UName );
Always fgets() to a temporary buffer, then extract what you need.
Both functions return status results, which later on you'll need to check for really robust code.
Step 1 - a loop which reads numbers and prints them out (this should be basically the same as a previous assignment)
Step 2 - make it exit on ctrl-z
Step 3 - make it reject out of range numbers
Got the idea yet?
Think about what steps you can
a) acomplish
b) might need to do first
When you've got somewhere (and got stuck), then post back.
Don't just stare at your "elephant" and complain that it's too big to eat all at once.
You should be set if you create a win32 GUI project.
So if you have
while ( cin.getline(input1, 31, '\n') ) {
cout << "--" << input1 << "--" << endl;
}
if ( cin.fail() ) {
cout << "Failed" << endl;
}
if ( cin.eof() ) {
cout << "EOF" << endl;
}
if ( cin.bad() ) {
cout << "bad, very bad" << endl;
}
If you use an arrow key, what happens here?
- loops a few times, then prints one of the exit messages?
- loops a few times, printing various fragments of the edited input, then goes back to waiting.
http://www.cppreference.com/wiki/io/fail
To get out of the loop, press ctrl-d, and you should see EOF printed.
If the code keeps in the loop, but prints various fragments of the line in several attempts, you should be able to recover.
Oh, and please find a way of copying the code accurately (pen drive, email yourself, whatever). It'll save a lot of confusion in the long run.
Are you just making stuff up without bothering to read the manuals?
The threads of a single process can use a critical section object for mutual-exclusion synchronization. The process is responsible for allocating the memory used by a critical section object, which it can do by declaring a variable of type CRITICAL_SECTION. Before using a critical section, some thread of the process must call InitializeCriticalSection or InitializeCriticalSectionAndSpinCount to initialize the object.
Do you do this - nope
> cvDestroyWindow( VidLeft );
> cvReleaseCapture( &capture );
Did you bother to wait for the threads to exit, before deleting all the resources those threads depend on - nope.
The rug is pulled from underneath the threads before they even begin.
How about starting with a tutorial?
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html