Skip to content
Code Project
CODE PROJECT For Those Who Code

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • C/C++

    c++ help
    10
    0 Votes
    10 Posts
    1 Views
    C
    CP is now ground for homeworks for free? RTFM.
  • 0 Votes
    3 Posts
    0 Views
    C
    Or VARIANT, if it's Win32.
  • have to modify a prn file which is generated by printer

    c++ help
    5
    0 Votes
    5 Posts
    0 Views
    S
    1. google for barcode reader source code 2. google for barcode printing source code 3. feed the former with your .prn file and get the code it represents 4. feed that to the latter to generate a new .prn file. GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
  • C++ Vector Array in Template

    help tutorial c++ graphics data-structures
    5
    0 Votes
    5 Posts
    0 Views
    CPalliniC
    Yes, Stephan ;P THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
  • Automatic Transfer File [Real-TIme]

    help
    3
    0 Votes
    3 Posts
    0 Views
    L
    Irwan Saifranto wrote: i don.t know what must i do A few possibilities come to mind. Choose a different subject, one that you do understand. Research the use of UDP sockets, and how to write your own data management protocol. Switch to TCP and research some of the many samples available on the internet.
  • Keyboard Arrow Key Control in C++

    c++ tutorial
    3
    0 Votes
    3 Posts
    0 Views
    D
    Member 11004573 wrote: Please Tell Me How To CONTROL KEYBOARD ARROW key... Are you wanting to "click" the arrow keys programmatically, or are you wanting to handle key clicks? :confused: "One man's wage rise is another man's price increase." - Harold Wilson "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
  • Strange Syntax

    css data-structures question
    4
    0 Votes
    4 Posts
    0 Views
    CPalliniC
    You are welcome. THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
  • can be p[-1] dereferenced?

    question
    7
    0 Votes
    7 Posts
    0 Views
    S
    Hi, int main() { char *p = "Test"; p++; p++; printf("%s", p[-1]); getchar(); return 0; } Suppose think the starting address of p will be 0x20000, You are incrementing p two times, so before entering to the highlighted line in above code value of p is 0x20002 and the content in that location as starting address will be st. Then p[-1] means *(p-1), means value at 0x20001 location. means 'e'. In printf, %s is a format specifier wich will try to display the string at the memory location provided in variable list. Here the address provided in variable list is value of *(p-1), i.e, 'e' (internally this is 0x65). So %s dereferences the value at 0x65, so some garbage value it will print finally. otherwise will terminate the program as memory is un referenced. Thanks
  • Calculute average value of large array

    algorithms data-structures question
    5
    0 Votes
    5 Posts
    0 Views
    S
    I've taken the link provided above (about cumulative average) as an inspiration to calculate the average incrementally, in a way that no intermediate value gets larger than about three times the maximum absolute value being added. Since I wasn't sure about various effects, such as the current average going negative, I added some test code and asserts to verify it actually works as intended. See the code below: #define TEST_RANGE #ifdef TEST_RANGE #include void minmax(const double newval, double&minv, double&maxv) { if (newval < minv) minv = newval; else if (newval > maxv) maxv = newval; } #endif template basetype average(const container_iterator& start, const container_iterator& end) { basetype cumulated_average = 0; basetype cumulated_remainder = 0; basetype addendum = 0; #ifdef TEST_RANGE double real_avg = 0.0; double val_min = *start; double val_max = *start; double avg_min = cumulated_average; double avg_max = cumulated_average; double rem_min = cumulated_remainder; double rem_max = cumulated_remainder; #endif long long n_values = 0; for (auto pvalue = start; pvalue != end; ++pvalue) { ++n_values; addendum = cumulated_remainder - cumulated_average + *pvalue; cumulated_average += addendum/n_values; cumulated_remainder = addendum%n_values; #ifdef TEST_RANGE real_avg += *pvalue; assert((char)(n_values*cumulated_average + cumulated_remainder - real_avg) == 0); minmax(*pvalue, val_min, val_max); minmax(cumulated_average, avg_min, avg_max); minmax(cumulated_remainder, rem_min, rem_max); #endif } #ifdef TEST_RANGE assert (fabs(n_values*cumulated_average - real_avg) < n_values); real_avg /= (double)n_values; #endif return cumulated_average; } void test_average() { char cvalues[] = { 13,7,-27, 34, -3, 22, 33, -1, 18, 29, 13,7,-27, 34, -3, 22, 33, -1, 18, 29, 13,7,-27, 34, -3, 22, 33, -1, 18, 29, 13,7,-27, 34, -3, 22, 33, -1, 18, 29, 13,7,-27, 34, -3, 22, 33, -1, 18, 29 }; auto cavg = average(cvalues+0, cvalues+50); } The last line is how it's used. For passing the values, you can pass any pair of iterators that delimit the range, including simple pointers (as I've done here), provided that these iterators can be incremented and dereferenced. In this example
  • 0 Votes
    6 Posts
    0 Views
    P
    It is, quite probably. fgets (not std::string constructor as I initially posted) is behaving different if I set different options for Optimization and Runtime Library in MSVS2005. I can't make Release work like Debug though, even setting the same options.
  • 0 Votes
    5 Posts
    0 Views
    S
    Hi Gokul, I understood your doubt. Here i am trying to clarify why it is happening clearly. printf("\n %s %d %f %c", "Gokul", 90,100,'X'); in the above piece of code if you observe clearly, with the assumption of starting address will be 0x1000, the contents of your piece of code will occupy memory as follows. "Gokul"- at 0x1000 90 - at 0x1006 100 - at 0x1010 'X' - at 0x1015 Now as per your format specifiers first %s will fetch first 6 Bytes("Gokul"), %d will fetch next 4 bytes of data as integer, so fetches 90, now %f means it will fetch next 8 Bytes of data means from 0x1010 to 0x1017 which includes memory location of 'X' also, after fetching it will try to display float number but it won't display as no external coversion you are doing. So it will display 0.0000000 Then during this time we are at memory location 0x1018 in which some garbage value(Σ) will be there as we are not storing anything. Even though if you give some other character in place of 'X' also it will give same value(Σ) as garbage is there in 0x1018 location. if you change 100 to some float number or explicitly converted to float number((float)100), then it will occupy 8 bytes memory now. then no problems and no unwanted results you get. If any clarifications feel free to ask, you will get help definitely. Thank you.
  • When to delete a pointer (C++)...

    c++ performance tutorial question
    16
    0 Votes
    16 Posts
    2 Views
    S
    Hi, I think this may help you to get clarification, please see once. :) class student { int x; public: student() { x=0; } ~student() { cout<<"I am in student destructor\n"; } }; student* fun() { student *s = new student(); return s; } int main() { student *s = fun(); delete s; getchar(); return 0; }
  • 0 Votes
    7 Posts
    3 Views
    S
    Hi, Don't use so many loops unnecessarly, here is the one way to get your answer in optimistic way. int main() { long num,num1,i=0,sum=0; short remainder = 0; cout<<"Enter the number:"; cin>>num; num1=num; while(num!=0) { remainder = num % 10; num = num / 10; sum = sum + remainder; i++; } cout<<"The sum of the digits of the "<
  • can anyone help how to find summation of float number?

    help tutorial question
    28
    0 Votes
    28 Posts
    0 Views
    S
    hi, I don't know what's the use of summation in your code. If you want summation of float numbers generated numbers only means, the following piece of code is enough i guess.. See once srand(12345); float z=0.0; float a=0.2,y=0.0; int i; for(i=0;i<5;i++) { float b=((float)rand()/(float)(RAND_MAX))*a; printf("%f\n",b); z=z+b; } printf("summation:\\n%f\\n",z);
  • 0 Votes
    8 Posts
    2 Views
    _
    To support UNICODE, you need to use wchar_t instead of char. You also need to use the string functions that work on wchar_t like wcslen, wcscat etc. While defining string literals use the L prefix - L"Hello World" If you have a string that is already encoded as ASCII, you need to convert it to UNICODE. Simply typecasting will not work. You can use the MultiByteToWideChar[^] API to do the conversion. «_Superman_»  _I love work. It gives me something to do between weekends. _Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
  • what is zed doing here?

    database question
    11
    0 Votes
    11 Posts
    0 Views
    P
    You're welcome. :-D
  • 0 Votes
    6 Posts
    0 Views
    L
    Just try reading things a bit before posting here. Your other question (in the C# forum) is similar.
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    2 Posts
    0 Views
    _
    Here is the explanation of the datetime data type of WMI - http://msdn.microsoft.com/en-us/library/aa387237(v=vs.85).aspx[^] «_Superman_»  _I love work. It gives me something to do between weekends. _Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
  • how to correct this warning?

    tutorial question
    5
    0 Votes
    5 Posts
    0 Views
    _
    The format %s is used to output a null terminated string. The variable it expects is a char*. I can think of 2 possibilities. Since you haven't posted any relevant code, I'm only guessing here. First guess is that you're trying to print a string and are using an extra & character - char string[20]; printf("%s", &string); // The & is not needed here. Second guess is that you've received a char** as a function argument and trying to print it. void fun(char** arg) { printf("%s", *arg); // * is needed here. } It would be best if you can post the relevant code. «_Superman_»  _I love work. It gives me something to do between weekends. _Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C