try this
switch(x%2)
{
case 0: // even
default: // odd
}
try this
switch(x%2)
{
case 0: // even
default: // odd
}
In c++ the best way to avoid pointer problems is not to use pointers, or use smart pointers. Instead of writing your own linked list algorithms use std::vector (arrays) opr std::list (linked list) and those classes will handle all the pointers.
I get the same error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: page_nav
Filename: views/community_view.php
Line Number: 26
Microsoft doesn't call them "widgets" -- they are "controls". For example there are Edit Controls, Listbox Controls, etc. But yes, they are all there in win32 api.
What compiler do you want to use? If you are writing pure win32 api program then yes, you have to clean up after yourself otherwise it can cause memory leaks even after your program has closed. If that really concerns you then it might be better if you used something else, such as MFC, CLI/c++ Windows Forms, C#, or even VB.NET. Pure win32 api isn't easy to write and requires a lot of code/testing. The others I memtioned make life a lot easier for GUI programming.
You need to post the code you wrote if you expect anyone to answer your questions.
The program is attempting to access non-existant table values. Lets assume a.length() == 10, then when i == 10 the statement table[i][0] is out-of-bounds because there is no element table[10][0]. Arrays are numbered 0 to but not including the upper-bounds of the array, in this case 0 1, 2, 3, 4, 5, 6, 7, 8, and finally 9. There is no 10th element. If you say your program works with 1000 then it works only by coincidence, not because its correct.
Here is a code snippet I wrote some time ago, maybe it will help you with your question. As for the sub-directory question, see the example in my code snippet -- you have to test for them.
The code snippet was written in c++, so just ignore the code you may not understand and concentrate on the loops.
Entry* resizeArrayCopy(Entry*& fpBuffer, const size_t resizeStep, size_t &bufferSize)
{
Entry* pNewBuffer = new Entry[bufferSize + resizeStep];
if(pNewBuffer == NULL)
{
return NULL;
}
In the above, new does not return NULL, instead it throws an exception, If you want to test for NULL you have to add a try/catch block. Here is how to do it
Entry* resizeArrayCopy(Entry*& fpBuffer, const size_t resizeStep, size_t &bufferSize)
{
Entry* pNewBuffer;
try
{
pNewBuffer = new Entry[bufferSize + resizeStep];
}
catch(bad_alloc xa) {
cout << "Allocation Failure\n";
return NULL;
}
There are several problems with that program. There may be other problems that I have not yet found.
void addEntry (Entry*& fpBuffer, int &elemCount,size_t &fBufferSize, size_t resizeStep);
My first password was probably "Waaaaaa!" -- when I was born :)
Is that all of the instructions you were given? I'm sort of surprised that your instructor didn't explain in greater detail what each of those methods were supposed to do.
The reason for the problem is because both FileTitle and FilePath are allocated on the stack, which disappears just as soon as the function returns. The solution is to pass the filename and path to the function as parameters so that they don't get destroyed when openFileDialog() returns.
BOOL OpenFileDialog(char*path, char* filename, bool InvertSlashes = false)
int main()
{
char path[_MAX_PATH];
char filename[_MAX_PATH];
OPENFILENAME of = OpenFileDialog(path, filename);
}
There is no data type between them. One thing you could do is pack the integers into an unsigned char buffer then unpack them when needed. That is going to be a huge performance problem though.
Here is the code:
We need YOUR code not Microsoft's code.
Those are the two best compilers/IDEs for MS-Windows operating system. Exactly what are the problems you are having?
I am currently using code::blocks but i am experinsing trouble trying to link the ws2_32.lib
Code::Bloocks doesn't use libraries with *.lib extension -- it uses *.a because CB is calling a *nix port of g++ compiler. You need to link with libws2_32.a, not ws2_32.lib
You want to create a win32 console project.
Yes --
You did not create a c++ project -- you created a CLI/C++ which is a different language.
As far as i know, System is a C# header.
No -- its also used in CLI/C++ which is another .NET language like C#. CLI/C++, C# and VC.NET are very similar languages
VC++ 2010 defaults to precompiled headers which requires stdafx.h. When you create a project you can uncheck that option. If the project is already created you can turn it off in Project --> Properties (last manu item under Projects).
Oh and if you know where to get a good tutorial about making a simple server-client side TCP chat program in C++ with winsock2.h
There is no such thing as a "simple tutorial".for that, and under MS-Windows you have no other choice but to use winsock. You might find some boost libraries to replace it. Also I have not use c++11 standards yet but it might also have something new. In any event you are going to need more than just a casual working knowledge of c++ to write that program.
@Captain: The link you posted is already on the second page. Press the left pointing < and it will take you back to the first page.
line 47: write(pipo, &arra[k], sizeof(arra));
Remove the & symvol -- arra[k] is already a pointer
line 55: free(arra[k]);
delete that line, arra can not be deleted.
fputs() is the opposite of fgets(), which is not what you want. You want to call strcpy() or strcpy_s() to duplicate a string.
lines 18 and 24 of server.c are wrong too. Remove the & symbol because its already a pointer.
If you are rich enough to buy one of those new electric cars, you most likely won't mind paying 8 to 10 bucks for gas/petrol.
Whata bet? I have a 2011 Toyota Prius that gets 48-52 mpg, but I still bitch about petro prices.
Neither of the code snippets you posted compile. This is your second example with a couple changes so that I could make it compile, but it also has a problem.
The operator << has two parameters, but main() is passing only one parameter. Fix that and both examples will compile.
#include <iostream>
using namespace std;
struct RGB
{
int R, G, B;
};
inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb)
{
Str<<"R: "<<(int)Rgb.R<<" G: "<<(int)Rgb.G<<" B: "<<(int)Rgb.B;
return Str;
}
int main()
{
RGB Rgb;
cout<<Rgb(16777215);
You can't actually code them as you posted them because the second line will produce a "redefination" error message. Once a macro has been defined you have to undefine it before it can be re-defined.
#define PRINT (a,b)cout<<(a)<<(b)
#undef PRINT
#define PRINT (a,b,c) cout<<(a)<<(b)<<(c) /*trouble?:redefines,does not overload*/
You don't have to define macros at the beginning of a program -- they can be defined, undefined, and re-defined anywhere you want to do it. The compiler will use the most recent definition when compiling the remainder of the program from the point that the macro is defined to the end of the program file.
Macros are evil beasts. One reason is because of what I just said above, that macros can be redefined anywhere in the program making it difficult for a programmer to figure out why something went wrong.
Are you certain p2 is an open FILE pointer?
if any process has the file open when this happens, deletion is postponed until all processes have closed the file.)" The part in parenthesis is what I take advatage of for this.
That is a BAD habbit to get into. That behavior doesn't work with all operating systems. For example remove() doesn't work like that on MS-Windows. Don't attempt to delete the file until AFTER you are finished with it and the file has been closed.
Should I still remove the spaces for %d and %s?
Yes. There should be no spaces between the % symbol and 'd' or 's'.
in regards to 104 thats where I was forgetting correct pointer syntax.
you want to call strcpy() to copy the string into name: strcpy(finder->name, symbol);
line 8: I'd make that an unsigned int instead of int because addresses should never be negative number.
line 41 p2 = fopen("argv[start]","r");
remove the quotes from around argv[start] -- the compiler thinks that is the actual filename, not a variable that contains the file name.
lines 35 and 36: Why are you opening a file then attempting to immediately delete it? unlink() will fail if the file is open.
line 44: Remove the spaces in the format specifier, e.g. it should be "%d%s". There should not be spaces between % and d or s.
line 44: Yes, the same line as above. The = EOF at the end should be == EOF because you want the boolean operator not the assignment operator.
line 104: That line is confusing. Why are you tring to store an integer in the first byte of a character array? That may work if the value of the integer is less than 126, which is the largest positive value that can be stored in a char data type. And is the first few bytes of variable symbol all numeric digits?
There are more than likely lots of other problems with that program I have not found.
line 11: start the value of j = i counter instead of 1
line 14: print the value of j not i, and do not increment it on that line. It will be incremented on line 11. Finally, put a space in the format specifier so that there is a space between the numbers printed on the screen.
Don't get me started of petrol prices in the UK ! I'm spending £60-£70 on the stuff in an average week at the moment.
I think I would ditch the auto and ride a bike. That's terrible price for petro.
The whole purpose of the up/down arrows is to let members vote anomously and avoid giving rep. IMO its just as easy to enter a comment if you want to give rep and I see no reason to change the system.
name == "James" || "Ellen" || "John") which || means OR, correct?
name == "James" || name == "Ellen" || name == "John"
When I have spare time (suitable for work, but beyond my 40 hour workweek), should I spend it improving my company's software or should I develop my own side projects?
depends on where you are at. If you are in your workplace then do company work because they own you and everything you do even if its beyond the normal 40-hour workweek. If you are somewhere else, then do anything you like -- don't do company work so that you don't get burned out. You need to rest and relax awhile every week. All work and no play makes for a very boring guy.
I was just able to successfully upvote,
Same here. Maybe he needed to hit the refresh button on his browser -- I have to do that occasionally.
call fgets() to get user input, then strtok() to break it up into individual words. I would just statically allocate the array of pointers to strings, for example char* strings[255] = {0};
. You could, as previously mentioned, also use a dynamically allocated array of pointers char** strings = 0
, but then you need to call malloc() and realloc() to expand the array to the desired size each time you want to add a new string to it. For small amounts of strings its just simpler and better to just use static allocation.
Possibly line 11 of main.cpp -- std: is a label, you want std:: (two colons, not just one).
The three set functions in the header file should be void functions because they do not return strings. Your compiler should be giving you warnings about that in the implementation *.cpp file., something like "function must return a value"
how about bumping threads several years old?
Narue has decided to retire her account on Daniweb
Again! She does that every now and then.
Will you be assigning a Super-Mod to taked Sanjay's place?
If x is a float or double printf() will think its an int because of the %d and try to print it accordingly. On 32-bit compilers the size of an int is 4 bytes while the size of a float is 6 bytes. You might even get strange results for all the other parameters because the float will screw up the order of the parameters on the stack. So if you have "%d%f" printf() will attempt to use some of the float as part of the string, which of course is wrong.
The main thing is to make sure the data types of the parameters match the items in the format. If x is an int then passing either x or &x might depend on the compiler you are using, because &x is a pointer. On some compilers pointers and ints are the same size, while on others, like Turbo C, they are different sizes.
The first thing I noticed while stepping (debugging) through your program is that you are pushing "." and ".." as well as other folder names onto the vector of files (see line 49). If the file is a folder then you don't want to do that.
Instead of main() passsing ".." to scan(), have main() call _getcwd() to get the current working directory and pass that to scan().
Then in scan(), the value of fullPath should just be the same as the parameter startDir
Here is the complete program I tested. Notice that I commented out a few things in main() that you may want to put back in. I didn't know what it was for su I just commented it out
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <ctime> // ctime_s()
#include <io.h> // _findfirst, etc.
#include <direct.h>
using namespace std;
vector<string> filesFound;
vector<string> scan( string const& filespec, string startDir, bool isRecursive )
{
intptr_t hFile;
_finddata_t fd;
// fix directory name
if( !startDir.empty() )
{
char last = startDir.back();
if( last != '/' && last != '\\' && last != ':' )
startDir += '/';
}
string findPath = startDir + filespec;
string fullPath = startDir; //findPath + "\\";
if( (hFile = _findfirst( findPath.c_str(), &fd )) == -1L )
{
cout << "No " << filespec << " files in current directory." << endl;
return filesFound;
}
do {
if( isRecursive &&
(fd.attrib & _A_SUBDIR) &&
fd.name != string(".") &&
fd.name != string("..") ) …
The reason of this behaviour is that the readfile read the file until get NULL
I think you misunderstood. ReadFile() reads in binary mode, the same as fstream.read() or in C fread(). You tell it how many bytes to read and it will read that many bytes, or until end-of-file. ReadFile() doesn't do text reads like c++ getline() or fgets().
findPath+fd.name );
Line 5: Check the value of findPath, does it contain a trailing / or \ ? If not then you need to put one there. Also check if the file was opened: if( in.is_open() ) {
Check the *.def file to make sure you exported that function.
ifstream in( );
line 36: Inside the parenthese you put the full path to the filename. But you have that line in the wrong place
do
{
if( !fd.attrib & _A_SUBDIR )
{
ifstream in(findPath+fd.name);
while( getline(in, line))
{
// blabla
}
}
} while( _findnext() );
)
Did you link with the *.lib file that was generated when you compiled the *.dll?
The only file you need in the test project folder is the *.dll. Actually, you can put it any of the folders listed in your PATH environment variable, such as c:\windows\system. As for the *.h file(s), just put the full path to where they are located in the include statement, e.g. #include "c:\mydir\test.h"
Application programs do not need any of the other files you mentioned.
Only limited way can class A use class B before class B is declared, class A can declare a pointer to an object of class B but that's about the extent of it.
class B; // pre-declare class
class A
{
public:
B* b; // declare a pointer to class B
};
You can't actually delete an element from the array. All you can do is mark it as an unused element. There are numerous ways to do that and it doesn't really matter which one you use as long as your program recognizes the element as being unused. For example, in the array you posted you could just set the word element of the array to an empty string, then when displaying all elements of the array if word is empty then just ignore it and move on to the next element.
This is what I have so far, where I'm I going wrong?
Don't know. What kind of problems are you having? If compiler error(s) then post the first two or three errors including the line numbers on which they appear.