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

Compile and run that example program that is given in the link that I posted -- it says it all. What you are trying to do is convert from char* to wchar_t* which is used for UNICODE (different languages such as English, Spanish, German, Russian, Japanese, Chinese, etc). CString class will not make the conversion for you, so you have to convert the buffer yourself before assigning it to a CString object. Pay particular attention to that mbstowcs_s() call.

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

>>CString str=(_T(buffer));

The _T macro only works with string literals, not character arrays. For example _T("Hello") If you want to convert a character array from char* to wchar_t* you have to use one of the convertion functions. Here is a thread that will show you how to do that.

The problem on line 3 of the code you posted is that you failed to use _T macro around those string literals.

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

You need to post code.

>>is usable outside of that function
Not necessarily. Depends on the code and how you pass the pointer between the functions. There are several ways to do it so we'd need to see you you tried to do it.

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

Input redirection is done at the command-line level, not from within a C program. If you want to redirect a file into the C program then the C program will want to read the data from stdin. You can still use Aia's example, but replacing file_handle with stdin.

There are ways to write your c program to get the data from either stdin or a file.

int main(int argc, char* argv[])
{
   FILE* file_handle = NULL;
   if( argc > 1) // file specified on the command-line
   {
       file_handle = fopen( argv[1], "r" );
       if( file_handle == NULL) // can't open the file
       {
            printf("Error\n");
            return EXIT_FAILURE;
       }
    }
    else
       file_handle = stdin; // assume file was redirected

    // now do all the reading
}

}

Aia commented: Very proper. +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have five options that I can think of right off-hand. How much effort you want to put into it depends on your goals -- just to satisfy a student course requirement or do you want to implement it on-the-job. Will it be just a one-time project, or are you going to use this program continuously over a long period of time.

  1. When you enter a student id read the file one line at a time, reading sequentially from beginning of the file to the end. With 500,000 records that might be somewhat time consuming, especially if you want a lot if id's.
  2. Get a list of all the ids you want to look for then searh the file for all of them at the same time. This will be a little faster than the first option because the file only has to be read once.
  3. Read the entire file into an array when the program starts then the program can search the in-memory array instead of the file. With today's computers and compilers reading 500,000 records into memory at one time will probably not be much a burden on system resources.
  4. If this is going to be an ongoing thing, such as use the file over a long period of time then you might consider indexing the file or rewriting it so that it has fixed-length records and is stored in sorted order. With that you could do a binary search algorithm to search the …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How to read from a text file depends on what you want to read. If you want to read an entire line at a time then follow Aia's example, but be aware that fgets() might put the '\n' at the end of the string, if one is found in the input stream.

Another way to read the file is one character at a time, using fgetchar(). But that is probably the most difficult way to do it. I much prefer fgets() and then parse the line for individual fields such as text or numeric data.

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

FOUR: If you want your code to be portable across operating systems and even compilers then don't do it in assembly. Assembly language is not portable. And inline assembly may not be portable between different compilers. Most C and C++ compilers today are smart enough to do a better job at producing assembly code than the majority of human coders.

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

use getline() instead of >> operator and it will work

int main()
{

    string serial = "0";

    while(serial != "")
    {
        cout << "Please enter serial number:" << endl;
    
        getline(cin,serial);
        
    }
    cout << "All done\n";
}

[edit]Oops! didn't see Nathan's reply [/edit]

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

Thanks for bumping a thread that's been dead for six years. ;)

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

{
int i = 25789;
char *p;
..............
..............
printf("%d",*p); /* (*p) should give in printf*/
}

dont assign p=i ............apart from this how we can typecast this program so that we can get interger value tp pointer p.............please help me this

This might work:

int i = 25789;
char *p = (char *)&i;

printf("%d\n", *(int*)p);
// The above is the same as this:
printf("%d\n", i);

If you want to show the address store in p instead of the integer then use %p, not %d printf("%p\n", p);

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

I agree -- that button is in a very poor location.

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

That big yellow button does no longer exist. Scroll down to the bottom of any forum menu page (the one in which you want to start a new thread) and you will see a button "Start a new thread"

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

>>meh. mine only shows some entries at the Department of Corrections.

Figures. You are probably one of the inmates in the men's federal prison located about 40 miles from my house :)

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

Its in the Software Development menu -- at the bottom.

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

>>Need a link back to the forum list

Unless I misunderstood, there already is a link back to the forum list near the top of the page.

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

People's real names are also google searchable. google your real name and you may also get some hits.

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

Even the title of this article is obnoxious-- a "wet dream" is what teenage boys experience. So are you trying to say that male programmers will ejeculate at the thought of iPhone 3.0?

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

I was going to say something really nasty but decided not to. Feel lucky that's all I said to you. And you are going to get negative rep from me every time you decide to spout off your fowel mouth.

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

OMG! I didn't know that -- guess I'll have to burn all my wife's purple cloths, toss away her purple nail polish, and repaint our purple bathroom. Make my house PC :)

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

Can everyone PLEASE stop incorrectly using the Quote tags on purpose. It makes things MUCH more confusing.

Just do for heaven's sake. Grr.

How is hitting the "Post Reply" button using quotes incorrectly?

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

Apparently Dani agreed with the OP:

Mobile Dev forum

Have fun.

Well then I think she needs to add a new forum for MS-Windows like I asked (and was rejected/ignored) over two years ago. There are hundreds of posts in the C and C++ forum that ask questions about win32 api.

jonsca commented: I'm for that! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are a number of ways to do it. One way is to use strtok() to find each segment of the string.

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

That is a compiler-specific function implemented mostly in *nix. But if you google for it you will find the first two links show you how to use it.

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

If you want the data displayed on the console sceen then pass cout like this: cust.displayLabel(cout);

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

printf("%d\n", *p.i); You have to use the * operator to print the value that i points to.

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

One way to do it is to print each byte one at a time in a loop. %s is for null terminated strings. What you apparently have is a binary file, not a text file. There is no standard C function that will print that entire buffer the way you want it.

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

You have to add the main() function that includes all the code that does the things you stated in your questions.

Will I write it for you? NO. You will learn nothing if I do that.

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

Did you find those terms used in a textbook you are reading? Indexed addressing would just mean accessing a specific element of an array with an integer variable.

int array[5];
int index = 1;
array[index] = 123; // indexed addressing mode

My guess is that indirect addressing would mean to use pointers

int array[5];
int* pointer = &array[1];
*pointer = 123; // indirect addressing mode
Aia commented: http://www.daniweb.com/forums/post1225270.html#post1225270 -2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> and also uses EncryPro for encrypting customer ID.

In USA customers do not have IDs. Only the cashier logs into the cash register with a user name and password, then he/she starts processing customers, checking/scanning each item, finally receives the money in the form of cash or check or credit/debit card.

Product Name: Bad idea. Should enter a UPC barcode instead so that the exact item, manufacturer, color, size and/or weight can be easily accounted for in the transaction.

As for taxes -- that is computed by the cash register when the cashier presses the Total button. There is no need for human to enter that amount. In my state there are two different kinds of taxes -- one for food (1.7%) and another for everything else (7.?%). Other states may not tax food. The taxes can get a little complicated which is why its better to let a computer calculate it.

How do I know? I am a cashier at WalMart.

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

I get the same problem. The link is http://www.daniweb.com/forums/post1221606.html#post1221606 which apparently is wrong. As I recall I think I tried to use permalink then copy from the address to the clipboard.

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

I got 7 pages of threads and all of them said they had 0 replies.

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

Nick: didn't mean to scare you -- I didn't think of it like that :)

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

Times are not getting updated. I made a post about a half hour ago and whan I returned just now the Last Post column said it was just 1 minute ago :) So I though maybe I just need to deleted temp internet files -- but that didn't fix the problem. I'm using IE8 on Win7.

[edit]Well now that I posted this thread I see the time on the other thread is now correct. [/edit]

Dam -- I hit the Post Reply button instead of the Edit/Delete button. Oh well. :)

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

Times are not getting updated. I made a post about a half hour ago and whan I returned just now the Last Post column said it was just 1 minute ago :) So I though maybe I just need to deleted temp internet files -- but that didn't fix the problem. I'm using IE8 on Win7.

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

Thank you for the vocabulary lesson :), but I actually understand what the word demand means in this thread...

Maybe if you cared to read my post well enough you would have noticed I mention your specific usage of the word in the first part of my sentence, and that the second mention between the double quotations has nothing to do with what it implies in your post or anyone's at all, intentionally.

Thanks again though.

[offtopic]
If I insulted you I am truly sorry -- there are a lot of members here whose mother thoung is something other than English, and English has a lot of suttle differences that they may or may not understand.

On the otherhand I've come across many people whose mother toung is something other than English who write English better than native English speakers. Propably because they have to study it more intensly. I know many native English speakers who can not put two words together to make a comprehensible sentence, and its getting worse with texting so widly used now.
[/offtopic]

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

IMHO ditch that crappy CSingleLock class and use CriticalSection since it works for you the way you want it to.

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

If you are using either VC++ 2008 or 2010 then to go menu item Project --> Propertiess (last item in the list), expand the Configuration Properties tab, General, then on the right side of the screen, third item from bottm change Character Set to Not Set AFAIK that's the only way to do it. I wish Microsoft had set an option in Options to make that the default.

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

Yup -- that's why I said there is no point reading the same line of the file 100 times.

I don't know the correct solution to your problem because I don't really understand the math. First sit down with pencil & paper and work out the math by hand. Once you understand the math then you can program it.

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

Much better :) Replace the header cstring with string. Your program uses nothing from string.h (cstring) but does use the c++ std::string class from string.

Well now all your program is doing is reading the first line of the file 100 times. What are you to do with all the rest of the data in that file? Your program might as well read the first line of the file once then call update() 100 times with the same values. Like this

double x0,x1,x2,x3,d; //declaring x0,x1,x2,x3,d

fin>>x0>>x1>>x2>>x3>>d;
for(int i=0; i<100; i++) //running loop 100times
{

    update(w0,w1,w2,w3,x0,x1,x2,x3,d); //updating weights
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> I'm not even to be considered an active user yet to have the right to "demand"...

I think you misunderstood the use of the word "demand". Nobody said or implied that you are demanding anything. Use of the word demand means something else entirely, such as "a large demand for katsup" means that there are a lot of people who want to buy katsup. That is the way the word demand is being used in this thread.

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

Please stop adding the line numbers yourself. The code tags will do that. If I want to copy/paste your code into my own compiler I have to delete those numbers that you posted. I did that the first time, but I'm not going to do it again. So repost the code without those numbers that you put there.

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

Why not? You see child windows with buttons etc. all the time, just look at your browser to see them in action. If you use FF or IE7/8 each of those tabs are just child windows.

You might want to investigate either CLR/C++ (Midrosoft Forms) or C# which will make you a lot more productive than using win32 api functions directly.

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

The reason you only get outpout of 0 is because of function eval(). Look at line 8 -- it sets all the weights to 0, destroying all the calculations done in main(). Comment, or delete, that line.

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

Yes it will cause a huge problem -- and that's why I posted that disclaimer. If the function is going to modify the string then probably either use a vector of char* or copy the contents of the std::string into a char* and pass that copy to the function.

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

Return in main is not required -- if absent the compiler will produce code to return 0.

>> is it legal to call main in a function
Yes and no. The compiler won't complain but its not supposed to be done. main() is the entry point into your program and should not be called from anywhere in your code.

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

You guys are amazing, just one problem... I get the error:
<<<cannot convert parameter 3 from 'const char *' to 'char *'>>>

Is there a variation of this function that returns char* instead of const char*? Thank you for all of your replys!

from helpfullprogrammer.

Have you not heard of type casts? foo((char*)client_message[i].c_str()); or foo( const_cast<char*>(client_message[i].c_str())); But you have to be careful about casting away the const, especially if function foo() wants to modify the contents of the string.

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

Hover your mouse over the [icode]

[code] tags on this thread and you will see a popup with the otherwise hidden code that the OP instended to post. It can only be viewed, it can not be otherwise copied to the clipboard.

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

When you enter a character on the keyboard you actually type two things -- the character and the Enter key. Right? Well, your program is not removing the '\n' cause by the Enter key from the keyboard buffer. Read this thread how to do that.

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

Towards the last half of the code you posted you have a bunch if multi-line if statements that are not surrounded by { and }.

if( something )
{
   // blabla
}
else if( somethingelse )
{
   // blabla
|
jonsca commented: Rep for wading through that +4