Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

test::open() is not the same function as the open function in that unistd.h. If you want to call the function in unistd.h than use the :: namespace operator, for example ::open(/* blabla */); HOWEVER, you are writing a c++ program then use c++ standard fstream objects instead of the very low-level open().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

we are not here to do your homework.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

They are two completly separate issues. There are example programs on MYSQL web site that show you how to use MSQL++. If you are new to win32 api programming then you have a bundle of learning to do. Here is a tutorial to get you started. By the time you finish this tutorial you will realize how to combine win32 and MYSQL++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

TCHAR is just a macro that is defined to be either char* or wchar_t*, depending on whether your program is compiled with UNICODE or not. If not UNICODE then use just simple assignment to convert to std::string. If the program is UNICODE then use one of the conversion functions, such as wcstombs(). That function works ok with English language, but I don't know about other languages.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It will work for the arguments you posted, but not for this

c:\myprogram /id TheAdminId /pw TheAdminPw
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

argc is the number of strings in the argv array. argv[0] is always the name of the executable program and will never ever contain a command-line argument.

>>argv + 3
all that does is bypass the first 3 characters of the ith string.

The algorithm you posted doesn't work at all if you put a space between "/id" and whatever is supposed to follow. For example, if you typed this:

c:\myprogram /id something <Enter key>

In the above the program will get two command-line arguments, not one. argv[1] will be "/cd" and argv[2] will be "something". And that will break the algorithm you posted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

there is no way using windows.h to do it?

One way is to use MFC, which has a picture control that lets you easily attach a picture (*.BMP file) to it. C# probably does too. I don't know how difficult is with plain-jane win32 api functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes. depends on what operating system, compiler and graphics library you are using. c++ itself doesn't support anythijng like that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

now that you stated your assignment problem, what are your questions?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

read the Read Me threads at the top of this board. They are filled with useful FAQ and other links for new want-to-be programmers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The alternative is to do it the old-fashioned way -- use malloc or new (depending on c or c++)

int foo(int size)
{
   char *array = new char[size];

  // blabla
  // now delete it
  delete[] array;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to post some code that illustrates what you are trying to do. Newest c++ standards allow for creating arrays with variables, but some compilers may not support this. For example

int foo(int size)
{
   char array[size];
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is another example program that might help you:
http://www.daniweb.com/code/snippet661.html

And just how do you expect a program that just displays "Hello World" is going to sort an array? :eek:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>how I go about using the numbers generated here later on in the program
1. use global variables (not recommended)

2. make the variables part of a c++ class

3. pass the variables around as parameters to the function(s) that need them.

>>way to get I to generate numbers with decimal values as well
make the variables of type float then divide the value returned by rand() by 100 to get two decimal places.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The fflush on line 45 is non-standard and may cause undefined behavior. fflush() is for flushing output streams, not input streams.

Is that a C or a C++ program? If it is supposed to be C then rename the file to *.c instead of *.cpp and the compiler will treat it as C program. Then you will have to move lines 40 and 41 to the top of the function.

>>line 60 fprintf(fp, "%c", lines[k]);

Since variable lines is a simple char array why not teat it as one? fprintf(fp, "%s\n", lines);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your problem is that the program is not aware of the std namespace. You have two choices:
1. after including the header files add this using namespace std; or add std:: in front of each object declaration. std::string filename

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use atoi() to convert ascii to integer, then use sprintf with "%x" format argument to convert the integer to hex string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what do you want to search for and what do you want to count? do you want to count the number of times "0012" appears in both lines (and the same for each of the other strings on line 1) ?

one way to do it is to create a structure that contains the word to search for and an integer that is the number of times that word appears in the other lines

struct count
{
    char word[20];
    int counter;
}

create and populate an array of those stuctures from the words in the first line, then read the second line and search each of the structures for the word. When found increment its counter, then go on to the next word in the second line. continue that until all the words have been read from the file. When finished, you will have a total frequency count for each word.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void CFoutTest::print(string text)
{
    fout<<text;
}

Everything compiled ok for me except above in red.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>char b[7]={98,120,97,113,122,121,101},

what is that? If you want to create a char array, do it the normal way so that you don't have to look up those numbers in an ascii table. And you don't have to specify the length unless you want the array to be larger than the initialization string. char b[] = "Hello"; There are a number of C sort algorithms that will sort the array -- the bubble sort is the easiest to code, but also the slowest. It can be coded in about 10 lines of code. Its ok on very small arrays such as what you are using. If you don't know how to code bubble sort just google for it and you will find lots of examples.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Any thoughts?

Nope, since you didn't post any relevant code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post the error message. and more of the code

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

select File --> New --> Project, then just follow the prompts in the dialog boxes, select Win32 console application radio button. The IDE will create the project with a *.cpp and *.h files. After than, select menu Build --> Build Solution.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

do you have your compiler set up to define UNICODE and _UNICODE macros? Otherwise, I don't know a thing about Chinese language.

Also, here is something I found with google. It appears your computer needs to have Chinese language installed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Nice and clean. Good way to manage your working projects, a "To-do" list then clean it up. I hate clutter

Someone once wrote "cluttered desktop, cluttered mind. Clean desktop empty mind" :cheesy: My desktop is very cluttered.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

inline code such a the remove() function should be limited to just one or two lines of code. Anything larger should be put in the implementation *.cpp file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't get any errors or warnings when compiled with my compiler -- VC++ 2005 Pro. Maybe you don't have your project set up correctly. Your code is ok.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is another example

#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
    HKEY hKey = 0;
    char buf[255] = {0};
    DWORD dwType = 0;
    DWORD dwBufSize = sizeof(buf);
    const char* subkey = "Software\\Microsoft\\Office\\PowerPoint\\AddIns\\MultiMgrAddIn.AddInDesigner1";

    if( RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS)
    {
        dwType = REG_SZ;
        if( RegQueryValueEx(hKey,"Description",0, &dwType, (BYTE*)buf, &dwBufSize) == ERROR_SUCCESS)
        {
            cout << "key value is '" << buf << "'\n";
        }
        else
            cout << "can not query for key value\n";
        RegCloseKey(hKey);

    }
    else
        cout << "Can not open key\n";
    cin.ignore();
       
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

although Ive opened the file using object.open("") the condition to check that there is indeed an open file always fails and i get my else message "file could not be found"

make sure the file d.txt is in the same directory (folder) as that the executable file is running. If they are not in the same directory then give the full path to the file in the open() function, for example if the file is located in c:\mydir then open the file like this: file.open("c:\\mydir\\d.txt"); the above assumes you are working on MS-Windows, if you are on *nix file.open("/mydir/d.txt");

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I thought the void ment no variable-values are taken to the separate function and none are returned.

It does mean that -- and the function is working as expected. But the void does NOT mean the function can't change global data.

>>test[10] = test[10] + 1;
array test only has 10 elements, numbered 0, 1, 2, 3, ... and 9. There is no 10th element number as you are attempting to use, so it is writing outside the bounds of the array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

GetOpenFileName will put that information in your szFile buffer. And it should be declared and initializedlike this: char szFile[_MAX_PATH] = {0};

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

please read the sticky posts (the threads with ReadMe in front of the subject) at the top of this board -- they contain a wealth of information for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

something like this example??

vector<stirng> array1;
vector<string> array2;
array1.push_back("Hello World");

// copy the first string in array1 into array2
array2.push_back(array1[0]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

never ever include one *.cpp file inside another one. #include's are only for header files with *.h extension and often with no extension at all. If your program consists of two or more *.cpp files then each file should be compiled as a distinct unit then finally all object files and libraries are linked together. How exactly to do that depends on the compiler you are using -- each compiler does this differently.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I fixed that now but I still have the un-expected file ending. Do you know why its doing this?

No you didn't -- curly braces still mismatched in your latest code just like they were in the original. Fix the braces and it will probably correct end-of-file error.

>>And they told me not use void main() but my teacher says we should
you need a different teacher because he/she doesn't know what he/she is talking about. void main has never ever been standard C or C++ syntax.


>>I looked for a bracket but I cannot find one missing
The program is missing two braces. One is the second do-loop is missing a close brace. I'm not certain where the other one is.

Suggestion: split your main() function into more than one function to keep the code short and easy for you to maintain, assuming you are allowed to do that. Your main() is just too big and unwieldly, and will give even most experienced programmers large head aches.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have mis-matched curly braces. The open brace on the do-loop is matched to the last close brace in the function. This is one reason I always place curly braces on lines by themselves so that they are easy to spot and match up. Some compilers IDEs and code editors, such as Microsoft VC++ and VI have macros that will show you the matching brace. Check you compiler's IDE to see if it has such a feature.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

no i cant, thats why im asking for someone hu can help me do thiis ,, its actually a problem,, twas given by our instructor and wants us to figure it out,, thats why ide like to gather any idea or information regarding this thing,,, tnx for the reply...

Go back and read the thread link that I posted, it contains the answer to your problem. If you don't understand the posted code to that thread then I doubt you are ready for the course you are taking. The proglem is a little too advanced for someone completly new to programming and C language in particular.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

theres a bbc america?

Yes, but they only run old BBC shows :sad:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> while(!feof(Entrada))
Delete that loop -- it is not needed because the loop using fgets() will take care of finding end-of-file.

>>But whats the name here in the code for array 1, and array2?
The code I posted is for array1. Is array2 in the same file or a different file? And does it have the same format as for array1?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> don't know how to separate it like this.
see frexp() in math.h

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dune my favorite si-fi movie. Dr Who my favorite si-fi tv series. We in US just saw the first epesode of Robbin Hood on BBC America last night. Looks like it will be a good series.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you need to declare a 2-dimensional character array whose dimensions can be allocated at runtime. char **array = 0; Next, after opening the input file read the first line which is the number of words in the array. That tells you the number of rows (the first dimension) to allocate.

int nWords = 0;
fscanf(Entrada, "%d", &nWords);
array = malloc( nWords * sizeof(char **));

Finally, read the remainder of the file

char inbuf[255];
int i = 0;
while( i < nWords && fgets(inbuf,sizeof(inbuf),Entrada) != NULL)
{
   // allocate memory for the new string
   array[i] = malloc(strlen(inbuf)+1);
   // remove the trailing '\n' that fgets() might
   // leave in the string
   if( inbuf[strlen(inbuf)-1] == '\n')
      inbuf[strlen(inbuf)-1] = 0;
   // copy to the array
   strcpy(array[i],inbuf);
   ++i;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Er he was born in apparment number 1950 on 25th street or summat silly like that?

Ah you are very very close. 1950 is the hospital room number.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Born on february leap year?

No. try thinking outside the box.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Anyone that was forn would be dead... He died in 1968. (or he knows a good worm-hole)

Oops! typo -- should have been born. But anyway he is still alive and well. Probably a student that asks questions on DaniWeb:mrgreen:

Hint: you will find the answer to this riddle in the movie "The Honnymooners"

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The year is 1968.

No -- he was 18 years old in 2007.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A man was forn in 1950 yet he is only 18 years old. How is that possible?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to post code because I can not see your monitor from where I am sitting :)

The most common reason the window closes quickly is because you did not add any code to make the window stop so that you can read it. If you are coding C program then add getchar() before the return statement in main().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>btw; the characters should be in a random order
sorry but your program does not work with a string like this: "abcabcdeab". That is what is meant by random order. But congratulations on finding your own solution :)