Hello anicent dragron, the code you posted doesn't work on my compiler. How do I make it work? :sad:
see Narue's post.
Hello anicent dragron, the code you posted doesn't work on my compiler. How do I make it work? :sad:
see Narue's post.
>transform(myString.begin(),myString.end(),myString.begin(),toupper);
Amazingly enough, that's correct, but I'm not sure if it's correct because you intended it to be or if it's correct because you messed up your headers.
some compilers may have problems with the code I posted for the reason you mentioned (ambiguity). The code you posted is indeed more portable between compilers.
I use Microsoft compiler(s) and the code I originally posted works with them.
u can use
for (i=0;s[i]!='\0';i++) s[i]=toupper(s[i]);
that may not work because std::string is NOT a null-terminated string. It does not use 0 to determine end of string.
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string myString ("abcd");
transform(myString.begin(),myString.end(),myString.begin(),toupper);
cout << myString << endl;
cin.ignore();
return 0;
}
loop is simple to do
std::string maxlen;
int n = 0;
do
{
cin >> maxlen;
n = atoi(maxlen.c_str());
if(n <= 0)
cout << "You've entered a wrong number, please try again." << endl;
} while( n <= 0);
Can someone tell me if its correct?
why do you need someone to tell you that? You can do it yourself just by running the program. Does it do what it is supposed to do? Yes, then it is correct. No, then you need to rewrite parts of it.
You can use the printer's device driver and win32 API OpenPrinter and associated functions. (Scroll down to the bottom of the page and you will find other links).
you can allocate a class just like you did for that array
class MyClass
{
// blabla
};
int n = 5;
// allocate an array of class objects
MyClass* pClass = new MyClass[n];
//
// allocate only one class object
MyClass* pClass = new MyClass;
1. put all the numbers in an array and short it.
2. create a 2d array, the first dimension contains the number and the second dimension contains a count of the number of times the number appears. The program will have to iterate through the original array (#1 above) and maintain each array in #2.
c++ <map> will facilitate #2 above, but I'm not familiar enough with it to demonstrate its use.
if you are using MS-Windows, create a shortcut then change the shortcut's icon.
RW[h] is just the h'th character in the array -- strcpy wants a pointer to a character array. make a character pointer as shown below -- assuming h is the index into the array where you want to copy the string.
strcpy(&RW[h],"if");
The second option (with pointer) will be most efficient and fastest because the first option makes a copy of the object before putting it into the vector while the second one does not. And depending on the contents of class C the first option can be very very slow.
The flip side is during destruction of the vector -- you must destroy (delete) each object in the vector yourself, the vector will do that with the first option but not the second.
yes. use a while loop and iterate through the array until the desired value is found or the loop counter reaches the maximum value of the array.
hi.. just want to ask if <fstream> is really needed in making a program for round robin scheduler? im currently taking my os class and our project is to make a code for RR.. :?:
fstream is not needed unless you want to save the data to a file on the hard drive.
i dont understand
Read your own program. That function has no parameters.
That error means the program is attempting to pass the wrong number of parameters. how many parameters to you see in that function? It doesn't have any parameters, yet your program is attempting to pass one parameter -- they have to be consistent.
what errors are you getting? I see a couple of missing semicolons -- your compiler should complain about them. Look at the errors, then look at your code and see if you can figure out what's wrong.
The Express edition will be free for only about a year -- after that people will have to pay the $54 or so for it.
Since you want to spend your money, buy Pro edition. The Express is FREE -- you can't buy it.
Depends on operating system. If you are using MS-Windows, you can use win32 api function CopyFile() -- see MSDN for details. To my limited knowledge of *nix, I don't think *nix compilers have a similary function. You might also check the Boost libraries to see if it has a portable function. If not, then write your own or use systenm() function to use the system's cp or copy function.
Here is simple code to get all the file names in a directory. It does not parse sub-directories.
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
strcpy (DirSpec, argv[1]);
strcat (DirSpec, "\\*");
HANDLE hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
do {
// If this filename is NOT a directory
if(!FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// do something with the filename
}
} while( !FindNextFile(hFile,&FindFileData);
FindClose(hFile);
use FindFirstFile() and FindNextFile() to loop through all the files in a directory. Search MSDN and you will find some examples.
Hello acient, thanks for your reply. I'm learning so much. However this works but it doesnt seem to get the data from the varibles.
I've added this code:
UpdateData(true); before everything else in the function. But it still prints out default values.
how did you pass recordings? The whole array as I had in my example? or just the relevent array element?
CShowRecordingsDlg dlg(m_aRec);
or
CShowRecordingsDlg dlg(&m_aRec[m_nRecCount]);
If you did the first example, then recordings-> will only point to the first array element. You will need to use the index of the element you want to display
ShowArtist.SetWindowText(m_recordings[index]m_sArtist);
string ponter = new string;
Now we have a ponter that is a string :)
no its not -- it is still just a pointer, it just contains the address of a c++ class.
A string is any finite sequence of characters (i.e., letters, numerals, symbols and punctuation marks).
There are two types of strings -- C and C++.
A c-style string is a null-terminated sequence of characters -- certainly considerably less than infinite! That means that the string ends with the first byte that contains 0.
The C++ string is a class in std library. There are other c++ string classes too, but the standard one is in std namespace.
Most controls are derived from CWnd class, and all of them have SetWindowText() method. Use the control's SetWindowText method to show text
ShowArtist.SetWindowText(m_recordings->m_sArtist);
swap the string with out using any library functions
you will have to
1. create a temporary buffer large enough to hold the longest string.
2. write your own strcpy() function -- but name it something else to avoid confusion with standard C function.
3. Then use the function you wrote in 2 above to copy the string to a temp buffer and swap them
void mystrcpy(char* to,const char* from)
{
// copy the string one character at a time
}
int main()
{
char temp[255];
char s1[255] = "Hello World";
char s2[255] = "Another World";
mystrcpy(temp,s1);
mystrcpy(s1,s2);
mystrcpy(s2,temp);
}
You could still use CEdit -- make it read-only and set its value in the OnInitDialog() method (or someplate else). Alternatively you could use a CStatic control. They don't have scroll bars, so if the text is too big you won't be able to see part of it. A read-only CEdit is better for large amounts of text so that the user can use the scroll bars (set them in the property)
you can't contantinate C style character arrays like that. Create a third buffer that is _MAX_PATH bytes long (if you are using MS-Windows os, I don't know what it is on *nix), then use sprintf() to create the string. Remember the format string uses "%s" for strings and "%d" for integers. so if you are formatting a string that will contain another string and an integer, the format specifier for sprintf() will be "%s%d".
I forget to mention that you need to add includes in the .h file(s). Attached is the project that compiles cleanly. I didn't add anything to display the array -- just to pass the array.
and change the function as shown below
void CRecordingUIDlg::OnOnShowRecording()
{
CShowRecordingsDlg dlg(m_aRec);
dlg.DoModal();
MessageBox(NULL, m_aRec[0].m_sArtist);
// TODO: Add your control notification handler code here
}
If you haven't already figured it out yourself, you will need to pass the array to ShowRecordingsDlg constructor so that it can have access to the information.,
// ShowRecordingsDlg.h
class CShowRecordingsDlg : public CDialog
{
DECLARE_DYNAMIC(CShowRecordingsDlg)
public:
CShowRecordingsDlg(CRecording* recordings,CWnd* pParent = NULL); // standard constructor
virtual ~CShowRecordingsDlg();
// Dialog Data
enum { IDD = IDD_SHOWRECORDING };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
CRecording* m_recordings;
public:
CEdit ShowArtist;
CEdit ShowTitle;
CEdit ShowLenght;
int m_nIndex;
afx_msg void Forwardbtn();
void display();
};
// ShowRecordingsDlg.cpp
CShowRecordingsDlg::CShowRecordingsDlg(CRecording* recordings,CWnd* pParent /*=NULL*/)
: CDialog(CShowRecordingsDlg::IDD, pParent)
{
m_nIndex = 0;
m_recordings = recordings;
}
Make the above and the dialog will have access to the entire array. Create an OnInitDialog() event handler and populate the dialog's controls there.
>>return (a + b + c) / 2;
should divide by 3, not 2.
I see no ambiguity in the average template -- all parameters are of type T and the caller cannot pass the first as int, the second as float and the third as double. All three must be of the same type or the compiler will shout at you very loudly :)
>>can you told me the latest C compiler which i can used for the same.
Here are two: Dev-C++ is probably best for learning because it has the simplest IDE that doesn't require a lot of time to learn.
Then you will want to search goodle for ODBC -- that is how most (but not all) programs access databases. There are some c++ ODBC classes here -- just enter ODBC in its search engine and you will find them.
now create the switch statement -- its easier than an if-then-else statement
switch(num)
{
case 1:
cout << "one" << endl;
break;
case 2:
// you can figure out the rest
}
Yes, I know a lot about MFC -- the compiler creates one of two sub-directories under the directory that contains the source file(s) -- <source>/debug for debug builds and <source>/release for release builds. Both directories contain all the *.objs, *.sbrs, *.pch and several other compiler-generated files. You need to delete those directories because they are huge.
It is not necessary to add system *.lib files to the source directory.
The actual source file(s) in your project should zip up to only a few hundred K, well under one meg, unless you have a really really huge project consisting of several hundred *.cpp and *.h files.
People will be more willing to download your project if you strip it of all the unnecessary files before zipping.
did you delete the debug and/or release directories before you zipped of those files? And what compiler/version did you use?
I don't think you can even do it with a driver. Turco C programs are 16-bit programs that run in a SIMULATED MS-DOS box (simulated in all version of MS-Windows except Win95/Win98). They have the same limitations as all other 16-bit Turbo C programs -- 640K max, segmented arceture, memory models, etc.
Ditch that old ancient compiler and expand your knowledge by learning to use modern compilers. This is not 1980.
I HAVE SQL 2000?
you definitely cannot use it with Turbo C. Get a modern compiler.
you can use std::string object in socket programming. just use its c_str() method to convert from std::string to char*.
>> I had tried simply accessing it that way, but for some reason it wasn't recv()'d correctly.
Then there is something else wrong with your program. you should look elsewhere for the error. just make sure the last byte of the buffer is a 0, to terminate the string.
they are identical.
you don't need strcpy() at all
char sendBuffer[5];
char ch;
// assume code in between makes ch something
sendBuff[0] = ch;
sendBuff[1] = 0;
Wolfpack's program works ok with Dev-C++ too. I have version 4.9.9.2, but some previous versions should work too.
you can't access most databases, such as Microsoft Access, SQL Server, MySql, Orical, etc, with that old 16-bit Turbo C compiler. You will have to upgrade to a modern 32-bit compiler, such as Dev-C++. Then you have several options, the oldest is ODBC. google for ODBC and you will find lots of information.
Of course if you want to store simple data, then you don't really need a formal database, just store it in files.
you can't use flat memory model in real mode because segmentation is different. You can use a dos extender, such as Pharlap, that switches back and forth between real and protected mode, but your flat memory model program runs in protected mode, not real mode. The dos extender switches to real mode in order to service real mode interrupts, such as incoming data on serial ports and network cards.
10 years ago there were several brands of dos extenders, but I don't know if any of them exist today.
I havn't had a bathtub bath in over 20 years -- I hate the thought of sitting in all that dirty water, not that I'm really all that dirty, but all that soap scum soaking into my skin -- yuuuuk!
I agree that a delete button would be useful -- I have occationally posted bad information and the only way to delete it was to edit the post and remove all the code, leaving a post with an empty message.
use qsort, std::sort(), or some other sort algorithm to sort the array normally then just print the values out in the desired order.
look in the CDocument-derived class for your project -- it contains a skelletin of Serialize() function that you have to compilete (make it actually do something useful). This is where you read/write the data that you want saved to a file, database, socket connection, or anywhere you wish.
Yes there are better compilers (some free but most cost lots of $$$), but Dev-C++ is probably best for beginners. Most of the other compilers have complicated IDEs (programmers GUI editors and tools) that take some time even for experienced programmers to learn. Stick with someting pretty simple for now.