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

What operating system and what compiler ? The easiest way to capture the Enter key would be to use the non-standard functions in conio.h, but your compiler may or may not support that.

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

You can not get the source code from binary exe files. The best you can do is disassemble the program to get assembly language source files.

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

GUI and RS232 serial port program are unrelated. Here is a list of the Windows Communications Functions. Start out by calling CreateFile() to open the serial port, then BuildCommDCB() to set up the port configuration (stop bits, data bits, parity, etc). Then ReadFile() to read from the port and WriteFile() to write to the port.

Here is a more thorough explanation with a few sample programs

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

One way to do it is to use GNU regexp C libraries, but those may be overkill for what you want to do.

Another way is to write your own parser. For example if you enter "*Bill*" or "Bi?ll" The * means to match all characters up to the string "Bill", while the ? means to match anything for just a single character.

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

Those errors seem to be coming from Microsoft include files. I suspect its caused by something in your own program. Post the complete UltraReadDlg.cpp file, or at least the first 20-30 lines that show all the includes. You might also have to inspect the contents of stdafx.h file, if you have changed it since the compiler originally generated it.

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

The problem is that p will be pointing to some out-of-range memory location and that has nothing at all to do with whether its of type T or not. You will get the same error if you try to do the same thing in a simple C program. C and C++ languages do not normally support storing data before the address of the array, although it is common to do that in BSTR data types (Microsoft specific data type). Some other languages such as VB might do that too.

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

which files? In which folders? Please be more specific.

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

What are the errors and warnings?? We can't read your mind or see your computer, so you have to be specific and tell us.

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

Yes you can write C code with that compiler, providing you named the file *.c instead of *.cpp. If the file is named *.cpp then the compiler will treat it as C++, not C.

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

set and get: depends. If the variables are private then yes the class will need them if something else wants to set or get their values. IMHO its good to use them regardless so that there is only one place in the entire program where the class variables can be changed. If you ever have to change something then there is only one place to change it.

About 2d array: yes you will get compiler error. Initialize the array in the class constructor(s).

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

VB can access any dll written in C language, but C++ DLLs have to have special handling, such as the DLL either has to use extern "C" to make the DLL exported functions C style functions or the VB program has to know about name mangling, and you will have to do that manually. It depends on how the C++ dll was written and what compiler was used to generate the DLL. There is no standard way for compilers to mangle names.

Here are some threads you should review.

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

cin.get() will not work either if there are still keystroks in the keyboard buffer. You will have to flush them out first. Here is a thread that shows you how to do that.


[edit]Oops! same as ^^^ said.

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

>>allows structs, but not objects.
string is an object, or more technically called c++ class.

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

SqLite doesn't throw exceptions, it just returns errors. You will have to change SqLite source code to make it throw exceptions like what you want. You have all the source code so you can change it any way you like.

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

Yes they should return an int, but the author probably omitted that just to simplify the code and illustrate the intended problem.

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

My statement still stands -- it makes no sense to compare author and title. You need to do something like this:

void record_search(const char *filename)
{
//  fflush(stdin); <<< non-standard
  char author[sizeof(data.author)+1];
  char *ptr;
  FILE *file = fopen(filename, "rb");
  if(file != NULL) {
    struct record data;

    printf("\n   Enter book author: ");
    fflush(stdout);
    fgets(author,sizeof(author),stdin);
    //getline(data.author, sizeof data.author); <<< no such function in C language
    // remove trailiing '\n' that fgets() inserts into the sttring
    ptr = strchr(author,'\n');
    if( ptr != NULL)
       *ptr = '\0';


    while(fread(&data, sizeof data, 1, file) == sizeof(data)) {
    if( strcmp(data.author, author) == 0)
      printf("%s,%s,%s\n", data.author,data.title,data.isbn);
    }
    
    
    fclose(file);
  }
}

Also, your example shows a comma separated text file. In that case you do not want to use binary file techniques so the above code won't work. Read each line using fgets() then split it into its individual parts by parsing that line to find each comma, such as strchr().

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

You could try this or this to get examples

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

why would you want to compare a person's name with the title of a book?

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

use strcmp() to compare the two.

BTW: C language does not have a getline() function. You have to call fgets() to do that.

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

Yes you will have to compare the author's name you type with the records found in that loop. Warning! do NOT use the same data item for both as you have posted on line 10. Use a different character array for that purpose so that its contents do not get destroy during the fread() loop.

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

what is the difference of tab and spaces?is not the same?i thought its the same with the difference that at one you press one button only

They are not the same thing. A tab is a single character '\t' which can be interpreted differently by different IDEs and operating systems. When you replace tabs with spaces in your code it changes it from "Hello\tWorld" to "Hello........World" there each . is a space (DaniWeb forums removes extra spaces so I had to replace them with . character.

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

Do all the other characters in the MS-Windows os appear correctly in French? In otherwords, are you using English or French operating system? Have you tried asking that question on Microsoft's programming forums, which are often answered by Microsoft technicians?

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

have you tried SetLocale()

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

As with many other things there are no right or wrong answers to the questions you have asked. One programmer may do it one way while another programmer will do it some other way. Its all a matter of personal preferences, or in some cases, company coding policy.

1. Generally, yes that's true. But there are always exceptions, and those should be very rare.

2. As long as you don't overdo them, such as writing a function that does nothing but write HelloWorld to the console window. I had an interview with one company whose coding policy was to put no more than one if statement in a function. That was going beyone what I believe to be the extreme right end of the line.

3. An alternative is to put all those parameters into a structure and pass a pointer to the structure.

4. I had one supervisor that couldn't even read C/C++ so I had to comment every line. The code looked horrible to me, but I had to give the boss what he wanted. At a minimum there should be a comment at the beginning of each function that explains the purpose of the function and possibly explain each of the arguments. Comments should appear elsewhee in the function to explain difficult-to-follow code.

5. Absolutely yes! The more practice you get the better and easier it will become. Great violinists do not become so great by playing computer games all the time.

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

Oops! should have been while(fread(&data, sizeof data, 1, file) > 0)

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

>> since name of the file is of LPSTR type I need to convert char[] to CString

No you don't. LPSTR is defined in windows.h as char*, so there is no need to convert char* to CString just for that purpose.

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

You may want to look at using the substr method and the find method for std::strings to help break strings apart.

I already suggested that yesterday, but I think using stringstream is a better solution.

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

The file probably contains more than one record, so you have to use a loop to read each of the records until end-of-file is found.

while( fread(&data, sizeof data, 1, file) == sizeof(data) )
    printf("%s\n", data.title);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you are reading the file you need to open it with "rb" instead of "ab"

Also check the return value of fread() to see how many bytes were actually read.

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

All you have to do is replace fwrite() with fread(). I assume data is a struure with fixed-length character arrays instead of pointers.

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

CString has a Format() method that works exactly like sprintf(). Simplify your code like this:

CString m_strFileName.Format("%02d/%02d/%4d %02d:%02d:%02d",
  t.wDay,t.wMon,t.wYear, t.wHour,t.wMinute,t.wSecond);

Adding 5 to t.wHour can easily make t.wHour exceed 60.

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

>>And it outputs junk (mainly numbers like -147, 70, 8, 10), etc.

Exactly -- binary files can not always be read, which is why they are called binary files. You have to know how the binary file is formatted before you can make any sense out of them. For example, if the file were written like this

FILE* fp = fopen(filename, "wb");
int x = 123;
fwrite((char *)&x, sizeof(int), fp);

Then the only way to read the file is like this:

FILE* fp = fopen(filename, "rb");
int x;
fread((char *)&x, sizeof(int), fp);

or something like this

FILE* fp = fopen(filename, "rb");
int x;
char buffer[255];
int bufsize;
fseek(0, SEEK_END);
bufsize = fp.ftell();
fseek(0, SEEK_SET);

fread((char *)buffer,bufsize , fp);
x = *(int *)buffer;

Most binary files are a hell of a lot more complicated than the above. Show us how the file was written and we can show you how to read it.

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

Most likely because you failed to terminate the two strings on lines 5 and 6. How is putstr() supposed to know where the end of the string is? int 21 uses $ as a string terminator, while C and C++ languages use 0.

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

depends on the functions you are using to get the files in a folder. On MS-Windws using FindFirstFile() and FindNextFile(), see the fields in the WIN32_FIND_DATA structure. dwFileAttributes will tell you whether its a file or a folder.

Similar on *nix using opendir() and readdir() functions.

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

nice try, but that doesn't work. Example: Jan 1 -- 1%7 == 1, and we all know that the first of the month does not always fall on a Monday.

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

functions and structure in time.h will give you that information.

  1. First put the day, month and year in a struct tm structure. Then call mktime() to populate the rest of the structure. tm_wday contains the day of the week.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>but it doesnt work
What does that mean???

lines 13 and 14 could be both replaced by one line: jl end_if

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

You can use Code::Blocks on both MS-Windows and *nix

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

>>while (a!='q' || a!='Q')

Use && operator instead of ||. Read it as "while a not equal to 'q' and not equal to 'Q'"


>>expected before "return"

I think you will need a semicolon at the end of that line too because its the end of a do loop

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

text is a pointer to a character arrray. The star in front indicates dereference of the character. So if text == "Hello", then *text is looking at the first letter, 'H'. C strings are always terminated with the NULL character 0, or '\0'.

The while statement as written is poorly constructed. "{ *text++ == c|| c == ‘.’}" makes no sense. It should also use ( and ), not { and }.

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

don't use strtok() because it will put 0s in the std::string buffer, invalidating that buffer.

Instead, use std::string's find() method to locate the spaces, the substr() to extract the characters.

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

Under Internet Options --> Delete, I de-selected "Preserve Favorite Website Data" and now everything looks as it should. I thought just deleting temporary internet files would solve the problem, but it didn't.

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

Here is a snapshot

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

go to c++ forum and look at the last date and reaction columns. They are just wrong. For example the thread "Different Heaps" shows last date was 37 minutes ago and Reaction shows 1 post. Now click on that thread and look at the time of the last post -- it was sometime yesterday, and there are two posts, not just one.

Tick Tack Toe Using Classes thread is similar. There are 6 posts, but Reaction column shows 0.

Using IE8 I deleted all internet temp files but that didn't change anything.

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

>>if( (ch-48) >= 0 && (ch-48) <= 9)

replace that with: if( isdigit(ch) )

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

what do you mean "it doesn't work".

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

To complicate it a little more, the main program and DLL each have their own heaps (and memory managers), and that's why memory allocated in a DLL can not be released in the main program (or another DLL) and vice versa. I'm not sure if shared libraries on *nix work that way.

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

>>strTemp.Format(_T("item"), i + 1);

Format() function is very similar to sprintf() -- you need to add %d if you want the string to contain the value of i+1. strTemp.Format(_T("item %d"), i + 1);

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

That's not possible. Why? One reason is that getline() doesn't know, or care, what the size of the command window is. It reads everything up to the '\n', or some other character you specify.