And I have become confused on what this thread is about...
I'd wager it's about the OP boosting his post count with pointless posts.
And I have become confused on what this thread is about...
I'd wager it's about the OP boosting his post count with pointless posts.
So it is an ibiscus, an istory and a hibiscus, a history But I still don't know what the general writing rule is.
I'd write it the way I speak it, and recognize those cases where speech may vary when reading how others write. So in writing, "an LED" and "a LED" are equally correct because both pronunciations are equally correct.
The key to understand is that rules of writing aren't chiseled in stone; good writers will follow them in general, but break them without apology when doing so is justified. However, the difference between that and poor writing is an understanding of the rule and having a good reason for not following it.
1.if .net is a wrapper around win32 api it means we are able to do everything with .net that we used to do with win32 api. then why we still need the p/invoke to the win32 api?
Because there's not a .NET interface to all of the Win32 API. For some things you still need to call into the Win32 API through PInvoke. Accessing the message loop directly or "low level" windowing features, for example.
2.what are the limitations (in terms of programming) of .net compared to win32 api ?
Due to the abstraction of .NET, there can be performance issues. In such cases optimization techniques include dropping to a lower level with PInvoke or writing high performance pieces in something like C++.
I'd use the homepage more if Fred and the new discussion panels didn't take up so much room. Perhaps you could add a way to collapse those and store the preference in a cookie?
I'm here to ask a help because I am not a Expert like you I'm a newbie on C# program.
I'm happy to help, as evidenced by my posts in this thread. However, the purpose of helping is for you to learn. Eventually you should learn enough to not need to ask for help. As an example, I rarely ask others for help because I'm able to do research and think through my problems on my own.
When it seems like I'm being asked to do all of the work and thinking for you (such as fixing simple syntactic and semantic errors), I get the strong impression that you're not learning anything, and thus my help is pointless. If you can't do that much, you'll be right back here in no time asking for more "help".
I want a simple query to catering my needs.
At this point I'd question why you haven't managed to come up with something workable, or even something different from what you had originally. I've given you a lot of code, and plenty of ideas for moving forward. Barring doing it all for you including a sample database schema and complete working code, what more can I do for you?
I got my Hypocrite Medal during a battle of words on the C++ forum
It's not easy to be consistent. Also, one's opinions may change over time, which can smell like hypocrisy but is really just adjusting to new experiences and knowledge.
First and foremost, your code exhibits undefined behavior because you only ever initialize the first character of the string. The actual problem you're seeing though, is that you only store one character at a time in string[0]
, and it gets replaced with each iteration of the file reading loop.
The counter will only increment if the last character in the file is 'a'
, or the random memory used by string
happens to have an 'a'
in it.
A better approach would be to read a character, then check it:
int ch;
while ((ch = fgetc(f)) != EOF) {
if (ch == 'a') {
++counter;
}
}
fclose(f);
Let's begin by considering why arrays might be needed. What is the problem that this feature solves? How does it make your life as a programmer easier? When studying new features, it's important to recognize what that feature does for you and where the incentive is in using it. Otherwise you might learn a feature just because it's there, but never actually use it, or never learn it at all.
Fortunately, arrays are very easy to justify. Consider a small program that collects 5 names and displays them to the user:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name1, name2, name3, name4, name5;
int n = 0;
cout << "Enter 5 names (EOF to stop): ";
if (getline(cin, name1)) {
++n;
}
if (getline(cin, name2)) {
++n;
}
if (getline(cin, name3)) {
++n;
}
if (getline(cin, name4)) {
++n;
}
if (getline(cin, name5)) {
++n;
}
if (n > 0) {
cout << "Name 1: " << name1 << '\n';
}
if (n > 1) {
cout << "Name 2: " << name2 << '\n';
}
if (n > 2) {
cout << "Name 3: " << name3 << '\n';
}
if (n > 3) {
cout << "Name 4: " << name4 << '\n';
}
if (n > 4) {
cout << "Name 5: " << name5 << '\n';
}
}
We can immediately see that this is tedious and repetitive. It encourages copy/paste and is easy to make mistakes …
OkSoLve it if u can ;)
Done. Your turn.
When I import the DLL I have created into another project to test, it complains about missing the reference
System.Drawing.Bitmap
is a .NET standard class. The library assembly itself doesn't require you reference System.Drawing
in the application that references your library, but if you expose the Bitmap
class as a parameter or return value and require the application to recognize objects of it by type then the application does indeed need to reference System.Drawing
because now that dependency is in the application.
You can eliminate that dependency by writing a wrapper around Bitmap
within your library that only exposes features you'll be using. The application will use that class, and Bitmap
will be hidden within it.
Here's a related example. I wanted to use the Aspose barcode recognition library in a DLL without forcing the application to reference or license that library. There was one type I couldn't expose: BarCodeReadType
. What I did was create my own enumeration for the barcode type and my own Barcode
class to hold the data:
/// <summary>
/// Represents supported barcode symbologies.
/// </summary>
[Flags]
public enum BarcodeType : long
{
Codabar = BarCodeReadType.Codabar,
Code11 = BarCodeReadType.Code11,
Code128 = BarCodeReadType.Code128,
Code39Standard = BarCodeReadType.Code39Standard,
Code39Extended = BarCodeReadType.Code39Extended,
Code93Standard = BarCodeReadType.Code93Standard,
Code93Extended = BarCodeReadType.Code93Extended,
Datamatrix = BarCodeReadType.DataMatrix,
Ean13 = BarCodeReadType.EAN13,
Ean8 = BarCodeReadType.EAN8,
Patch = BarCodeReadType.PatchCode,
Pdf417 = BarCodeReadType.Pdf417,
Postnet = BarCodeReadType.Postnet,
Qr = BarCodeReadType.QR,
Upca = BarCodeReadType.UPCA,
Upce = BarCodeReadType.UPCE
}
/// <summary>
/// Contains information for extracted barcodes.
/// </summary>
public …
Oh really?
Yes. The bit pattern will be different depending on the endianness of the architecture. There aren't any rules aside from being aware of the architecture and matching it, but a common guideline for portable code is to always use the same endianness for sharing bytes regardless of the architecture. The application then reorders bytes to match its own architecture.
For example, you'll notice that internet standard transmissions are big endian to maintain consistency.
the language isn't changing at all. a lot of people are just either too lazy, too uninterested, or, in some cases, too dumb to learn and use it right.
Formal rules, good ones at least, are derived from common usage, so the language is indeed changing. Also, common usage tends to eliminate useless or awkward rules over time. Splitting infinitives and ending a sentence with a preposition are two good examples of awkward and unnecessary rules.
"Do not split infinitives" is a "rule" (note that it's technically not even a legitimate rule) taken from Latin then bastardized to fit English, but in Latin it's grammatically impossible to split an infinitive. In English it limits expressiveness and encourages awkward clauses.
"Do not end a sentence with a preposition" also damages expressiveness, and also happens to not be a legitimate rule. The reason for the rule is that a preposition ending is supposedly weak, but given the awkward sentence construction required to follow the rule in many cases, you end up with a weak sentence in general.
The me and I difference is quite subtle, and I prefer not to expect anyone to get it right. My biggest pet peeve is misuse of your/you're or their/they're/there.
I also have the benefit of many years of experience which have taught me that there are many cases where the slick or clever solution is not the desirable (ie maintainable) solution.
That's a good point. I've found (also through experience) to start with the simple and obvious solution and only get clever when that doesn't work out for some reason. The reason is usually performance, but that's not as common as some would have you believe.
No offense intended, but I don't like your OpenConCls. Here's a data access manager that I use for simplified database connections. Warning, it's a utility class, so there's a bunch of code. But first, an example of how to use it in the code you have:
private const string _provider = "MySql.Data.MySqlClient";
private const string _connectionString = "uid=root; database=membership; pooling = false; convert zero datetime=True";
private void Form1_Load(object sender, EventArgs e)
{
try
{
using (var db = new DataAccessManager(_provider, _connectionString))
{
var query =
"select top 1 piId" +
"from tblpair_individual_membership" +
"order by piId desc";
var result = db.Select(query);
if (result.Rows > 0)
{
_lastId = result[0]["piId"].ToString();
}
}
}
catch (DataAccessException ex)
{
// Handle the error
}
}
DataAccessManager
is generalized to any supported provider, which in your case is MySql.Data.MySqlClient
. Note that I haven't added scalar query support because I tend to need full DataTable
s, but it would be trivial to add. It's also optimized for SQL Server in terms of the connection string features, but the actual data access should work for any provider (including MySql).
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
namespace JRD.Utilities.Data
{
/// <summary>
/// Provides data provider agnostic queries and commands.
/// </summary>
public class DataAccessManager : IDisposable
{
private DbProviderFactory ProviderFactory { get; set; }
/// <summary>
/// Gets or sets the external data store provider name (ex. System.Data.SqlClient).
/// </summary>
public string ProviderName { get; set; }
/// …
I had one once with a knowledgeable programmer and some time later, he ceased to connect. I think he had too strong convictions and he wanted everybody to agree.
How much time is "some time"? Maybe he just left for other perfectly legitimate reasons. Even if your assumption about his motivation are accurate, it's impossible to avoid offending everyone. I'd much rather see civil airing of grievances and productive discussion than let things silently stew.
This thread is clearly inflammatory, but I'm letting it slide because there's potential for good discussion iff everyone remains civil. Please keep that in mind, thanks.
Are we slowly turning ourselves in robots?
You've asked this question with the implied assumption that the result is bad, which hasn't been convincingly argued. What's inherently wrong with being partially "robotic"? Until we have a basepoint for discussing the ramifications intelligently, we need to move away from irrational fears.
Let's get one thing clear first, are you using a hardware barcode scanner or do you need to recognize barcodes on an image that's stored on the file system? The two are different beasts, and the former will typically be easier because a hardware scanner will just give you a string on standard input whereas recognition from an image requires a certain measure of library support.
Also, what kind of barcode are we talking about? 1D, 2D?
Is a hard 5 digit sequence required? If all you need is something that's larger than the previous ID and smaller than the next, you can use the custom date time formatting to get a high enough resolution that practically guarantees uniqueness:
' Timestamp down to the millisecond
Id = DateTime.Now.ToString("yyMMddHHmmssFFF")
I'm going to go out on a limb and guess that what you want is to clear the screen when redrawing the menu. This will keep the menu in the same physical location for each iteration of the loop.
Since you're calling it "DOS" I can only assume you're using Windows, and as much as I abhore system
as a security hole, the easiest way to clear the screen is:
int menu()
{
int choose;
system("CLS");
do {
...
Don't forget to include <stdlib.h>
, that's where system
is declared.
There were a few changes to .NET Framework
4.5 support, which in the business world is a no-go until Windows 8 is adopted (unlikely in the near future from my consulting experience) or IT departments are comfortable installing the runtime to support applications written for it (more likely, but still a bit off). Right now the most my clients are typically willing to work with is the 4.0 framework and Windows 7.
closer compliance to C++11
Not close enough for my comfort. VS 2014 should be a solid implementation of C++11 and choice features from C++14.
I've written too many CSV parsers (real ones, not this naive comma split stuff) to be interested in doing it again. ;)
Cheating is a huge problem, and I understand it's not your problem, but you should reconsider your policies to help prevent it
Our policies already prevent the cheating that we can control. For the cheating we cannot control, school policies and disciplinary measures can easily take over without us deleting content.
Honestly, I'm somewhat confused as to what this teacher is trying to accomplish by having us destroy evidence.
Other websites I've contacted in the past were able to, and did, delete the content immediately
It's impossible to cater to the policies of every school and still be a useful resource for students, so we don't. Very simple.
Guys .. u thought that I never tried .. I tried alot.
Prove it. Not only does it show us that you're not just looking for a handout, but it also helps us to determine your level for tailoring help to you. Further, instead of a lot of back and forth, you might find that your problems are actually easy to fix when someone more experienced has a look at the code you have.
My opinion is that you can never, ever have too many program comments or step comments and a program with too many comments is much easier to debug, use, understand and share than one with not enough comments.
I strongly disagree. Excessive useless comments can be even worse than no comments.
it would help him to have too many rather than too few comments to explain the code; right?
That's fine, provided it's clear that the unusually verbose comments are being used to help a beginner understand things that would be obvious to everyone else.
Anyway, if you don't think comments are good then that is a great opinion for you
Way to completely misinterpret what I said. I love comments, they're awesome. But there's a condition that the comments must actually be helpful when reading code. For example:
void hello() // function called hello that returns void
{
cout << "Hello, world!\n";
} // End foo
Both comments are unnecessary. The first just says what anyone with even a passing knowledge of C++ would know from glancing at the code, and the second is so close to the start of the function that the purpose of an end marker is completely defeated.
I don't believe that such a thing exists as a program with too many comments.
I've had to maintain code bases with too many comments. "Too many" meaning all kinds of comments that are utterly useless for …
if (condition that evaluates to boolean)
{
// The condition was true
}
else
{
// The condition was false
}
I'm having trouble trying to grasp pseudocode.
It makes more sense when you realize that pseudocode has no rules. It's not going to be executed, so there's no compiler to satisfy. Just write something that makes sense to you and is consistent.
Pseudocode has no standard definition, just make something up. It could be as free form as:
declare an array of 20 integers
Or more rigid like an actual programming language:
declare array(20) of integer
On the surface it seems enticing, but the concept of immortality (or extreme longevity in this case) is usually more about fear of death than anything. If you really think about it, living so long would be more of a curse than a blessing. I suspect most people who took such a pill would end up suiciding long before reaching the age limit.
I have mix up pointers and by reference.
"By reference" in C is "by pointer". That's how you simulate pass by reference because there's not an actual reference type available. Pointers are close enough though, and colliquially we simply say that you're passing by reference instead of passing by simulated reference using a pointer. ;)
Can you help me to understand why void main() wouldn't work?
The only two signatures of main that the C standard specifies as universally correct are:
int main(void)
int main(int argc, char *argv[]);
Equivalent parts like char **argv
and different names for the parameters are acceptable as well.
Returning void
from main
is only supported by a subset of compilers, and if the compiler you're using doesn't support it, using void main
invokes undefined behavior. Undefined behavior is among the worst possible results for a program because it removes all predictability.
The actual error is that you're adding an unnecessary level of indirection in the tokenise call. tokens is already an array of pointers, there's no need for the address-of operator.
However, that said you still have issues in the program. Most notable is the next line tries to print tokens
as a single string when it's really an array of strings. You need to loop over the array and print each string individually. Further, tokenise
should return the number of tokens so that you know when to stop the loop.
Compare and contrast, I fixed other minor issues like including string.h
and not using void main
:
#include <stdio.h>
#include <string.h>
#define MAX_NUM_TOKENS 100
int tokenise(char inputLine[], char * tokens[]);
int main(void)
{
char inputLine[] = "Testing program Testing program";
char *tokens[MAX_NUM_TOKENS];
int n = tokenise(inputLine, tokens);
int i;
for (i = 0; i < n; i++) {
printf("token: %s\n", tokens[i]);
}
return 0;
}
int tokenise(char inputLine[], char * tokens[])
{
int i = 0;
char *pch;
pch = strtok(inputLine, " ");
while (pch != NULL)
{
tokens[i] = pch;
i++;
pch = strtok(NULL, " ");
}
return i;
}
It's like 3000 lines of code!
I only see 383 lines. Anyway, when I originally asked for code, I made sure to ask for a small but complete program that exhibits the problem. Some modicum of effort is required on your part to pare down the program to bare essentials so that it's easier to help you.
so is it correct to say that IN can not be necessarily used as a replacement from Exists, or reverse ?
in
can be used as a replacement for exists
in terms of functionality (may ways to do the same thing, of course). But if the result set of the subquery is large, exists
will be quite a bit faster since it's essentially taking a count that stops when a single match is found. in
will typically be faster when the result set is small.
returns all records form Customers table. Why ?
Because the subquery isn't keyed on the specific customer. You can think of these simple queries as an imperative foreach (not a perfect equivalence, but helps to visualize):
a = empty recordset
foreach customer in customers
b = empty resultset
foreach product in products
if product["prodCategory"] = 'Consumer electronics'
b = b + product
if b <> empty
a = a + customer
Notice that the inner loop doesn't look at the current customer record at all to determine its result set, so unless the table is empty, b
will always contain at least one record, and the exists
test will always evaluate to true. Therefore you'll always select every customer in the customers
table.
Now consider the same equivalence using the customer ID:
a = empty recordset
foreach customer in customers
b = empty resultset
foreach product in products
if product["prodCategory"] = 'Consumer electronics' AND product["cus_id"] = customer["cus_id"]
b …
let's put it in simple words, the subquery in this code will return on a boolean value TRUE, ok ?
It will select a matching record. exists
evaluates to a boolean based on the presence of any matches. But the rest of your explanation is reasonable, though not strictly correct (which is okay since you're putting it into simple words). I think the issue here may be less about exists
in particular and more about relational logic in general.
exists
looks for the first match in the subquery. If it returns true for any of the matches in the outer query, the where
clause succeeds and that record will be selected.
give me a link for read more about that magic numbers?
Magic numbers are just that, magic. They're selected completely at the discretion of the programmer, so there's really nothing to document in general about magic numbers beyond. A good library should hide any use of magic numbers from you anyway.
What I've been saying is that you need a very specific case to study, but this case is not a good one because merely using the magic numbers is a bad practice.
Instead, I think you'd be better off studying bit twiddling in general, rather than continuing with this specific usage. Try googling for "bit manipulation exercises".
i need to understand them because seems to be used in very situations.
In this case you don't. Someone gave you bad advice.
please give more information about these type of calculations.
First you need to figure out what those magic numbers represent. It's harder because they're intended to be opaque and not worked with directly here. Once you find out what each of the constants you want to work with represent, it's simple enough to figure out what the bit operations do for you using the corresponding truth tables.
but why these number and not other?
Magic numbers for bit twiddling are typically chosen to be unique bit patterns. For example, in the case of flags that are intended to be OR'd together you'd typically want to choose numbers where a single bit is set:
0x01 = 0000 0001
0x02 = 0000 0010
0x04 = 0000 0100
0x08 = 0000 1000
0x10 = 0001 0000
0x20 = 0010 0000
That way when they're OR'd together, you get a bit pattern that can easily be tested with AND.
The problem with your question is that you shouldn't be using magic numbers at all. Rather, you should be OR'ing together the manifest constants for those flags, even if it's more verbose. The constants are there because the magic numbers could change, and then code that uses the magic numbers would break.
You need to get the console text attributes before changing them, then reset them after you're done (either before or after setting the cursor position).
Allow me to ask the obvious question, why would you want to recursively read a file?
Looks fine to me. Though if you're not required to implement quicksort, I'd recommend simply using merge sort. Merge sort is better suited to linked lists because it doesn't require random access. Quicksort on a linked list is tricky to implement efficiently due to the random access component, especially if you're using a singly linked list.
But does the garbage collector doesn't take care of that?
The garbage collector takes care of memory for objects, but it doesn't know about internal resources allocated by the object. A good example is file handles. The garbage collector will clean up memory for a FileStream object, yet the file handle still needs to be closed.
A class implementation could put all of the cleanup code in the finalizer if there's no problem with waiting until the garbage collector gets around to cleaning up the object. The problem with that is that things like file handles should be disposed of as quickly as possible when you're done with them. That's what the IDisposable pattern is for: deterministic disposal of extraneous resources held by an object.
My only nitpick is a pet peeve in that SpeechSynthesizer implements IDisposable, which one should always respect:
using (var synth = new SpeechSynthesizer())
{
synth.Speak(message);
}
It's ironic that MSDN's own examples typically don't respect IDisposable, despite the common occurrance of the following note variation on the same documentation page:
"Always call Dispose before you release your last reference to the SpeechSynthesizer. Otherwise, the resources it is using will not be freed until the garbage collector calls the SpeechSynthesizer object's Finalize method."
Then again, MSDN historically hasn't been a provider of good example code. ;)
These examples are hideous. But let's break it down.
(((i+=3)&&(i++>6))||((++i>8)&&(i+=3))
i
starts as 3. Then it's immediately incremented by 3 (making it 6) and tested against 0. 6 is not equal to 0, so the first half of the &&
clause succeeds. i
is not greater than 6 so the second half fails, but i
still gets incremented to 7 afterward as the postfix increment is used.
Both sides of the ||
are tested because one might be true, so i
is then incremented before testing the left clause of the right hand &&
. This fails because i
is now 8, and the test is asking if i
is greater than 8. This is an &&
test, so the right hand clause doesn't need to be checked if the left hand clause fails, so i
is not incremented further by 3.
Both &&
statements failed, and i
remains 8, so your output is the body of the else clause.
for(i=0;i++<5;) a[i] = i*10;
for(--i;--i>0;)
printf("%d - %d \n",i,a[i]);
This one is relatively easy. In the first loop i
is always incremented, but only after testing against 5.
The end result is that a[0]
is never modified, but a[1]
through a[4]
are. At the end of the loop, i
is 6, so the second loop decrements it immediately to 5. Then the condition decrements it again before testing against 0. The result is that you have a perfect reversal of the first loop.
printmax((i++),(j++));
This …
i ment to put c i just changed it to counter so you guys knew what it was
That's a hint that it should be counter
in the first place rather than c
.
Yes a visual calendar similar to outlook is exactly what I am looking for but cannot find any information on the internet.
Have you tried...you know, being creative and stuff? The internet won't tell you how to solve every problem.
That's an issue with your code editor. If you can set the character set to something like Unicode, you should be good to go.
The good news is you can do it. The bad news is you have little choice but to use a platform dependent method to set the console into a wide character mode. For example:
#include <iostream>
#include <fcntl.h>
#include <io.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_U16TEXT);
wcout << L"glória vitória\n";
}
Daniweb is not a homework for free service. Please show some proof of effort if you want help.