This should fix that compiler error
const LinkedList::Iterator LinkedList::InsertAfter(Iterator& Iter, const ItemType& Item)
{
nodePtr nNode = new Node(Item, NULL, NULL);
Iter.node->next= nNode;
return(nNode);
}
This should fix that compiler error
const LinkedList::Iterator LinkedList::InsertAfter(Iterator& Iter, const ItemType& Item)
{
nodePtr nNode = new Node(Item, NULL, NULL);
Iter.node->next= nNode;
return(nNode);
}
>>scanf("%s",&Guess);
The "%s" tells scanf() that Guess is a pointer to a character array, not a single character. If all you want is a single character then call getchar() instead. (link)
If you want them to enter "open sesame", which is two words separated by a space, then its a lot easier to declare Guess as a character array then use fgets()
char Guess[80] = {0};
fgets( Guess, sizeof(Guess), stdin);
>>but whenever i try it crashes the program. I also cant use *iter.node->next, because it says which takes a right hand operand of type nodePtr.
That's not what I posted -- re-read my post, it requires the parentheses ()
It gets worse than that -- the size could be different between compilers on the same os and between operating systems.
The link you posted doesn't have any downloadable files -- its just a tutorial.
Just download the binaries from here, and unzip them into any directory you want. Then in your makefile use -I flag to point to that directory.
simple example:
#include <stdio.h>
void foo( FILE* out )
{
fprintf(out,"Hello World\n");
}
int main()
{
FILE* fp;
foo(stdout);
fp = fopen("test.txt", "wt");
foo(fp);
fclose(fp);
return 0;
}
In the test project you have either (1) include Engine.cpp so that it's compiled along with test.cpp, or (2) create either a DLL or static lib out of Engine.cpp, then link test project with that lib.
Post code because I can't see your monitor very well from where I am sitting.
new operator causes an exception if it cannot allocate the memory, so your check for NULL will not do anything. You need to put that line in a try/catch block. As an alternative, you can use nothrow (link) and leave that check in your code.
I would think you need to add the new node to the Iter parameter, not tail. (*Iter).next = nNode;
front is a function, so you need ()
#include <iostream>
#include <list>
using namespace std;
class Aircraft
{
public:
Aircraft(int i = 0) { flightNo = i; }
int getFlightNo() { return flightNo; }
void setFlightNo(int i) { flightNo = i; }
protected:
int flightNo;
};
int main()
{
list<Aircraft> landed;
landed.push_back(Aircraft(1));
landed.push_back(Aircraft(2));
cout << landed.front().getFlightNo() << "\n";
return 0;
}
Some c++ stl classes, such as string, vector, and list, return size_t in some of its methods. For example. std::vector size() returns size_t value. Some compilers (such as Microsoft) will produce warnings if you attempt to compare size_t with int or long.
If you want the output to go to two places (screen and file) then you will have to print it twice. Put the code in a function then pass it the stream object (either an opened FILE* pointer or stdout)
A better flu solution
>>Please note that #include <string> is only necessary for Borland. CODE::BLOCK and Dev-C++ do not need it.
That may be true, but its always good programming practice to include it anyway so that the code is portable across compilers.
There are no compilers thatt will do it. If you are running MS-Windows then view Task Manager while the program is running and it will tell you how much memory it is consuming.
There are a few win32 api functions that use embedded '\0', what they do is use two of them to indicate the end of the data. But there again they had to write their own function to parse the character array.
The read should work, but the write doesn't because you are trying to write binary data to the console screen. The number will have to be converted to ascii readable characters first.
char buf[20];
sprintf(buf,"%d", num);
fwrite(buf,strlen(buf),1,stdout); // but why?? this is the same as printf()
When I click on "Site Search" with empty search box the browser used to bring up another window that would let me select several options. That is no longer possible.
Most of the stuff you seen in your textbook will also probably apply to Vista. The major difference is in the include files. If you look towards the bottom of that link I posted you will find the include files you need and an example C program. It illustrates how to call _open() two ways: both with and without the pmode parameter.
O_RDWR is used by very low-level C _open() function. Most programmers today use higher-level FILE* functions in C or fstream c++ class. But if you read this link you will see that O_RDWR is NOT one of the pmode flags -- pmode refers to permissions and is useful only when creating a new file.
Thanks!
Since I don't know much about Multithreading,
There's no better time than the present to learn. Write a simple console program that does nothing much more than create another thread and wait for it to finish. That is enough to show you how threads work -- its not really all that hard to do. CreateThread() parameters look complicated, but most of them can be set to NULL.
Its done almost like you posted it. Post what you have tried so that we can see what you might be doing wrong. You have to include <string>, and its lower-case "string", not "String". C++ is case sensitive, so you have to be careful about using capital letters.
Maybe the image is too big? I changed mine just yesterday with no problems.
To delete an item from an array just move everything up one element so that the one you want to delete is overwritten. For instance, if you have an array of 10 integers and you want to delete the first one, then copy #1 to #0, #2 to #1, etc.
a) Flag Bad Post does not affect post count.
b) Already asked for that awhile back but they shot it down.
You are about 20 years too late.
list is NOT a class or structure, therefore it has no methods, such as CharAt(). You may be confusing a character array with c++'s std::string class. Just use [] to index into a character array reverse = list[i] + reverse;
But that doesn't work either for a similar reason -- you can not append to a character array like that. If you want to add something to the beginning of a character array you have to move everything right one character to open up the room for the new character. Note that strcpy() will not work here because sourcee and destination are overlapping addresses.
for (i = 0; i < N; i++)
{
// move everything right 1 position
memmov( reverse+1, reverse, strlen(reverse)+1)
reverse[0] = list[i];
}
void clearString(char *string)
{
memset(string, '\0', sizeof(string));
}
That will not work because sizeof( any pointer here ) always = 4 with 32-bit compilers. To erase a character array all you have to do is set the first character to 0.
> string home(getenv("HOME"));
Also, it will crash when getenv() returns NULL; Better to make that two statements so that you can check for NULL.
>>"a:p:f:rlhc"
I had to add another colon after the r in order to make that work right. "a:p:f:r:lhc"
Why are you mixing FILE and fstream in the same program? Since this is a c++ program you should replace FILE with fstream.
I tried to compile that with vc++ 2008 Express on MS-Windows and got the following error. Maybe that is why your program seg faults, because there were compile errors that you failed to fix
1>c:\dvlp\test1\test1\test1.cpp(52) : error C2065: 'files' : undeclared identifier
1>c:\dvlp\test1\test1\test1.cpp(53) : error C2065: 'files' : undeclared identifier
[edit]see post #6, which answered that problem a 6 days ago ago![/edit]
>>This is what i have but not working?????????
Well, what is it that is not working? Doesn't it compile? If not then what are the error message(s)? And what compiler are you using ?
I implemented something like that (I think) many years ago with MS-DOS 6.X. It was a series of functions that performed context stack switching so that there could be any number of "threads". Unlike modern-day MS-Windows or *nix, the program would switch contexts only when requested by the currently running thread. So instead of running threads like you described -- A_1 B_1 A-2 B_2 etc. it might run something like A-1 A-2 A-3 A-4 B-1 B-2 A-5 A-6 B-3 B-4 B-5 etc.
.NET is not a programming language. I'm not quite sure just what it is but its part of MS-Windows os. Maybe you mean c++/CLR??
Anupa: If it doesn't work for you then you are doing something wrong. Start another thread and post the problem you are having.
In C language, a string and a character array are normally the same thing, unless specifically told that the character array contains binary data.
>>I think I need to find the size of the array, but I forget how to do that.
The best you can do is find the string length. The function strlen() will return that for you.
Give me the free download link please.
I already did -- just click the link I posted. Click on "yes it is free"
but eVC++ is also not free
and i think it is outdated already.
No it isn't. Depends on the operating system that's running on the mobile device. eVC++ 4.0 uses PocketPC, while VC++ 2005/8 uses Mobile 5.0 or 6.0 In addition to these compilers you have to have an SDK that is supplied by the manufacturer of the mobile device.
>>int countCharacter(char desired, char[] list)
The [] is in the wrong place -- should be char list[]
eVC++ isn't really all that much different than VC++ 2008 Express. c++ is c++ is c++. Once you learn c++ on desktop its pretty easy to develop with eVC++. There are some things that eVC++ does not support (at least prior to version 4.0) -- some of them are:
Line 28:
1) use a different loop counter name because it is hiding the loop counter declared on line 18.
2) why does that loop begin at 2 instead of 0, such as like this? for(int j = 0; j < nrAttend; ++j)
Each line in the data file represents the high and low temps for the corresponding month, such as the first line is for January, second line for Feb, third line is March, etc. So all you have to do is have an integer that counts the lines read. So the first line read would display month[0]
int count = 0;
while (inData>>temp_highs>>temp_lows)
{
outData<<month[count]<<" "<<temp_highs<<" "<<temp_lows
<<"\n"; // new line here
++count; // increment the counter
}
No way around it if you want to use normal string handling functions found in string.h and stdio.h. You will have to treat the character array as containing binary data.
Well, I suppose you could create the string to contain normal decimal values such as char num[] = "01";
>>I don't like smiley faces.
:);):D:-O:S:ooh::sweat::icon_eek:
Error numbers mean absolutely nothing because they are compiler specific. Post the actual error message for those numbers -- most compilers print messages as well as error numbers.
>>outData<<month<<" "<<temp_highs<<" "<<temp_lows<<endl;
month is a 2d array of strings. How else do you expect that statement to behave??? If you want it to print the month name then you have to tell it which one, like month[0].
Check the parameter list again -- according to function prototype the 4th parameter for averagehigh() is supposed to be ifstream but you are passing ofstream. You need to correct one of the two.
1) Learn to format code in a readable style.
2) Remove all those unnecessary header files. You can always add some back when you need them.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string str;
bool password();
void doCrypt(char *einput)
{
system("CLS");
ifstream in;
ofstream out;
char c;
string fileContent;
in.open(einput);
if(in.fail()) {
in.close();
cout <<"Could not find file: "<<einput<<endl;
system("PAUSE");
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type \"m\" for the command menu.\n";
return;
}
while(in.get(c))
{
fileContent += c;
}
in.close();
for(size_t i = 0; i < fileContent.size(); i++)
{
fileContent[i] += 0x4f;
}
out.open(einput, ios::trunc);
out << fileContent;
out.close();
cout <<"FILE ENCRYPTED!\n";
system("PAUSE");
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type \"m\" for the command menu.\n";
return;
}
void doDcrypt(char *einput)
{
system("CLS");
ifstream in;
ofstream out;
char c;
string fileContent;
in.open(einput);
if(in.fail())
{
in.close();
cout <<"Could not find file: "<<einput<<endl;
system("PAUSE");
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type \"m\" for the command menu.\n";
return;
}
while(in.get(c))
{
fileContent += c;
for(size_t i = 0; i < fileContent.size(); i++)
{
fileContent[i] -= 0x4f;
}
}
in.close();
out.open(einput, ios::trunc);
out << fileContent;
out.close();
cout <<"FILE DECRYPTED!\n";
system("PAUSE");
system("CLS");
cout <<"*-----------------------------------*\n"
<<"| Welcome to Crypto! |\n"
<<"*-----------------------------------*\n";
cout <<"Please type a command.\n"
<<"Type \"m\" for the command menu.\n";
return;
}
int main(int argc, char* argv[])
{
char einput[20];
//Problems Start Here
//<------------------------------------------------------------------------------>
char …
wrong forum