To do this, you have to use Win32 (Windows API).
Um...to determine the OS you need to use the Windows API? Doesn't that presume that the OS is Windows and then you're just drilling down to the exact version? ;)
To do this, you have to use Win32 (Windows API).
Um...to determine the OS you need to use the Windows API? Doesn't that presume that the OS is Windows and then you're just drilling down to the exact version? ;)
there was a lot of examples but dont specify the answer why i need p=&s.
Because the pointer needs to point to an object. A pointer is nothing more than a variable that holds an address; if you don't give a pointer an address, it's completely useless. p = &s
is the code that gives the pointer p
the address of s
. Then whenever you dereference p
, you're actually accessing the object s
.
That's why I suggested that you work on the concept of pointers, because if you understand the concept, the answer to your question is obvious. If you don't understand pointers, no amount of answers to the specific question will help until the overarching concept is understood.
what i meant by web is vedio tutorials and asking question in forums.
That doesn't refute my statement about quality. ;)
trying to avoid books and learn as much as i can from the web
The problem with that is the quality on the web is hugely variable. You can find great stuff, but more often than not it's crap by people who know only a smidge more than you do.
Give this one a try.
books are boring ,you know that.
As an avid collector of books, I would disagree. ;)
what do you mean by that???
Pointers point somewhere, right? Where do you think your pointer points? If the answer is "I don't know", it's not a valid pointer. It's fairly obvious that you don't understand the concept of pointers, so I'll direct you to your nearest beginner's book on C. They usually have a full chapter or two devoted to the topic.
p_array
is a pointer. When you use the subscript operator, that pointer is dereferenced. In other words p_array[index]
is functionally identical to *(p_array + index)
. Now, when you dereference p_array, the result is also a pointer, specifically a pointer to char. So this line is correct because the %s specifier of printf() expects a pointer to char:
printf("%s\n", p_array[index]);
If you further dereference the pointer, you get a char value (not a pointer). The reason you're getting an access violation is because printf() treats that value as an address, because you told it using the %s specifier that you were providing a valid address in the form of a pointer. In other words, you lied to printf(). ;)
then whats the difference between using namespace and #include?
The two are unrelated. Any confusion you might have about them could stem from thinking that they're somehow comparable in functionality.
number *p;'
p->count=0;
This is a classic error with pointers. A pointer MUST point to a valid object that you own. If the pointer is uninitialized, as in the two lines above, you CANNOT dereference it...period, full stop, no exceptions.
Once you initialize the pointer, all will be well, aside from the syntactic craziness of this line:
printf("%s",p->count)count;
Which should look like this:
/* Also note that I changed %s to %d because p->count is an int */
printf("%d", p->count);
Taking it of course!
I asked because inventing questions for an exam that you're going to take is absolutely nonsensical; the questions you come up with are extremely unlikely to be on the exam. It's also open book, so aside from knowing enough of the material to find details in your references, I fail to see how thinking up an unrelated practice exam could possibly improve your chances of passing the actual exam.
Are you creating the exam or taking it?
How to call a C++ function which is compiled with C++ compiler in C code?
The function must either be compiled with C compatibility in place or wrapped in such a function, otherwise C won't be able to recognize it due to C++'s name mangling conventions:
extern "C" {
void foo()
{
// Do C++ stuff
}
}
Then you can link with the resulting object code from C and call the function successfully.
You need to break the line up such that the ID can be compared. If subsequent details also need to be treated separately then strcmp() and strtok() come to mind as a viable first attempt:
#include <stdio.h>
#include <string.h>
#define WHITESPACE " \t\n\r\f\v"
int main(void)
{
FILE *in = fopen("test.txt", "r");
if (in) {
char id[70];
fputs("Please enter a student ID: ", stdout);
fflush(stdout);
if (scanf("%69s", id) == 1) {
char line[BUFSIZ];
while (fgets(line, sizeof line, in)) {
char *tok = strtok(line, WHITESPACE);
if (strcmp(id, tok) == 0) {
/* Woot! Matched the ID, print the rest of the details */
printf("Found student ID [%s]:\n", id);
while (tok = strtok(NULL, WHITESPACE))
printf("\t'%s'\n", tok);
}
}
}
fclose(in);
}
return 0;
}
I get an error message about MDAC 2.6 or greater needs to be installed.
Have you tried installing MDAC 2.6 or later? While I wouldn't recommend Access as your database, simply because it's not scalable and I've had bad experiences upgrading people who started with Access to a real database, the problem isn't your database or your connection string. We get a similar error even using SQL Server when the machine doesn't have the appropriate components installed.
Top down means starting at the highest reasonable level and then digging into details. It's an overall structure based approach rather than bottom up, which is more of a progressively evolving functionality approach (starting with the details and working up).
deceptikon: thanks for that, but i'm unable to match my SOURCE[8] to the const char *src you have used.
It was an example only, I'm not doing your work for you. You'll obviously need to adjust the algorithm to suit your source and destination arrays.
Can u help me?
Yes.
Somehow I get the impression that he wants numeric values rather than strings. In that case it would be necessary to either convert the string to a number or build the number directly. For example:
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
int digit_value(char ch)
{
const std::string digits = "0123456789abcdef";
std::string::const_iterator it = std::find(digits.begin(), digits.end(), ch);
if (it == digits.end())
return -1;
return it - digits.begin();
}
int main()
{
const char *src = "39 04 7d";
while (*src) {
if (isspace(*src)) {
++src;
continue;
}
unsigned char value = 0;
value = digit_value(*src++);
value = 16 * value + digit_value(*src++);
std::cout<< (int)value <<'\n';
}
}
Then I suggest you search google for some existing programs or write your own.
There aren't equivalent headers unless you're using a compatibility layer. A better approach would be to port your code based on features, and look for equivalent features in the Windows APIs.
Debugger shows this as 1515804759 in Decimal. that is when 5958595a taken as a whole.
why doesn't it show 87888990 like when they are take separately?
Because eax is being interpreted as an integer value instead of an array, so all four bytes are a single entity totaling to 1515804759 rather than separate entities {87,88,89,90}.
Why is it shown as 5a,59,58,57 rather than 57,58........ ? (because W=57 which comes first)
and why is it 5A after the 59 in hex? (I know that 10 is A,11 is B etc..... but not this)
Um...what? You know that A comes after 9, so how is 5a after 59 confusing? The rules of the positional numbering system don't change just because there are more significant digits present. The jump to 60 doesn't happen until after F, because hexadecimal has 16 distinct values per digit place: 59, 5a, 5b, 5c, 5d, 5e, 5f, 60.
It seems like you're stuck in a decimal mindset. The only reason 10 comes after 9 in decimal is because there aren't are only ten values that can be represented by a single digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. If you add more values, the need for 10 is delayed. If you remove values (such as in octal or binary) then the need for 10 is accelerated. If you think about 10 being the value that happens when you run out of unique single …
I'll echo Davey and say that there are no such plans that I'm aware of. On top of video tutorials being largely useless for programmers (in my opinion) unless they're very pointed demonstrations of tools or more of a computer sciencey lecture, it would also introduce the technical issue of both hosting video content on our server and providing embedded playback on the site.
Finally, the question of content itself is unknown. Would we be able to create or solicit enough content to justify the feature?
I think the storage space required is the most prohibitive hurdle to overcome before this feature can even be considered.
Oh and by the way, is it okay to post in purple? Like i just did now?
It's okay, but you're technically not posting "in purple". You're posting with heading tags, which may change their look and feel to be something other than purple. If that ever happens, full posts using heading tags could become unreadable.
Just an FYI, using formatting for purposes other than intended could be counterproductive as the site evolves. We've had issues with that before under vBulletin and code tags for plain text. Dani changed the way things worked and out workaround suddenly broke. ;)
If it is not there, that should be a new site feature :)
It might be tricky to break things down that way, and we try to avoid complex database queries for performance reasons. It's also something of a balancing act to provide enough information to be useful without making people uncomfortable about the easily accessible public information concerning their activity.
However, with that said, if you're interested in specific members you can jump into their public profile and see more detailed stats.
I thought Visual studio 2010 compiler is not open source therefore I won't be able to find thoses files there
These are template classes. Without getting too much into it, due to the way templates are implemented, it's drastically more efficient to keep all of the code together rather than separating declarations and definitions. So template classes are nearly always implemented fully in the header file. Provided the header is actually stored as a viewable file, you can look at the code.
Isn't 'iostream' a part of the c++ library? why do some people call the <iostream> a library, not a file of the standard libarary?
Because everyone knows what you mean when you say the iostream library, there's no ambiguity. Why waste time with a pedantic description when there's no need? There may also be a historical reason, where there were originally many different libraries (of which iostream was one), and they were basically collected into the current "standard" library.
Is actualy code different for each OS but the functionalty is the same?
The code is different for each compiler, even compilers on the same OS. But the functionality is defined by a standard rules document that all compilers must adhere to.
If I want some software which can be compiled as part of my application / project etc, something which has little or no reliance on external programs (all packed in as part of my program) then what is that called.
I'd call it standalone software, assuming you mean a complete program that's self-contained yet still hosted on an operating system. If the program itself acts as its own operating system then it would be either an operating system or an embedeed program, depending on whether the primary purpose is hosting other programs or simply bootstrapping itself, respectively.
1.If cin and cout objects are in the 'iostream' , why do we need to declare it again using 'std' ?
<iostream> is the header that contains declarations. Without those declarations your compiler doesn't know that the names you use exist. The names themselves are declared within a namespace to avoid collision with other libraries.
Headers and namespaces are not used for the same purpose. In this case you're "declaring" namespace std to save you the trouble of constantly using the fully qualified name each time. Otherwise you'd end up typing std::cout
instead of just cout
.
2.are cout,cin,cerr,clog the only ones in the iostream?
Yes (including wide counterparts). But keep in mind that there's a metric shit ton of scaffolding behind those objects, which you'll find in headers such as <ios>, <istream>, and <ostream>. <iostream> is conceptually just the header that defines the objects cout, cin, cerr, and clog. But those objects have types which are defined in other headers.
The <iostream> header can be as little as this:
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}
3.under which categories do cin,cout and iostream fall? (library,object etc..)
cin and cout are objects in the standard I/O library.
…4.can we use the same iostream for both linux and windows? how come?
Can someone explain why this would be a good idea?
It's a little more natural syntax for setters and getters.
It seems like a lot of work for little benifit.
Indeed. I personally wouldn't use it unless the problem domain suggests a distinct benefit, but I also have a tendency to oversimplify. ;) Properties are nice to have, but generally only if the language supports them natively.
shall I post the actual code?
Please do, if it's not excessively long.
@deceptikon
I would like to read your opinion on comparison of java and .net
I'm not confident that I could provide a good comparison, even if you offered specific scenarios. My expertise in .NET is a full revision behind and my knowledge of Java is even more outdated.
if career in .net is not bad option then chances of learning java will decrease by 10%
Having at least a basic understanding of both would be the ideal situation, but both Java based development and .NET based development are viable career paths.
I am so happy I've quit .Net because Java is really fun !!! :-)
I'm happy that you're happy, but it's obvious that most of your bullet points for why Java is better are heavily opinionated to the point of propaganda. Some are off topic (eg. Tomcat being "better" than IIS), correspond to points that could be made equally for .NET (eg. "cool embedded stuff" and a "nice sound API"), or are just completely irrelevant (a cool mascot?). Even the ones that are legitimate reek of bias.
A proper comparison should be completely objective. The person doing the comparison should focus on specific needs (because obviously these two general solutions won't apply equally in all cases), and should be an expert in both so as not to skew the comparison with ignorance. Anything else just ends up being "I like XYZ, so you should like it too".
You could declare a char[BUFSIZ]. It is a max length your system can use.
Um...no. BUFSIZ is a macro representing the size of the default buffer used by the stdio library. It's nearly always a great deal less than the maximum length string you could define. BUFSIZ also doesn't preclude you from using a longer string with the stdio library, it's only there to give the library something to work with when the programmer doesn't provide a buffer with setbuf(). And the buffer is only used for performance purposes within the library, functionality doesn't change even when stdio is unbuffered.
However, BUFSIZ is usually large enough to represent a reasonable default buffer size for the programmer. Common values are 512 and 1024, so if you want something "finite, but large enough" in less than robust programs, BUFSIZ is often an acceptable choice. I use it for test and example programs regularly. ;)
You've cut and pasted parts of the code but neglected to modify everything. For example, in the file_w part of the code you're still working with fileread rather than filewrite. Compare and contrast with this corrected code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
FILE *file_r, *file_w;
int c;
char fileread[40];
char filewrite[40];
printf("Enter filename to be copied: ");
fgets(fileread, 40, stdin);
fileread[strlen(fileread)-1] = '\0';
file_r = fopen(fileread, "r");
while(file_r == NULL)
{
printf("Invalid file, ealnter again!");
fgets(fileread, 40, stdin);
fileread[strlen(fileread)-1] = '\0';
printf("%s\n", fileread);
file_r = fopen(fileread, "r");
}
printf("Enter name of file copy");
fgets(filewrite, 40, stdin);
filewrite[strlen(filewrite)-1] = '\0';
file_w = fopen(filewrite, "w");
while(file_w == NULL)
{
printf("Invalid Filename enter again");
fgets(filewrite, 40, stdin);
filewrite[strlen(filewrite)-1] = '\0';
file_r = fopen(filewrite, "w");
}
c = getc(file_r);
while(c != EOF)
{
putc( c, file_w);
c = getc(file_r);
}
fclose(file_r);
fclose(file_w);
printf("Files succesfully copied");
return 0;
}
but then i thought what if the user inputs a 2 digit number or a 3 digit number?
You'd need to extract tokens rather than characters. For example:
#include <ctype.h>
#include <stdio.h>
#include <string.h>
typedef enum token { UNKNOWN, VALUE, OPERATOR, VARIABLE } token_t;
token_t next_token(char buf[], size_t size)
{
const char *operators = "+-*/()";
token_t type = UNKNOWN;
int ch, i = 0;
while (i < size - 1 && (ch = getc(stdin)) != EOF && ch != '\n') {
if (isspace(ch))
continue;
/* Ignore negative values for brevity */
if (isdigit(ch)) {
if (type == UNKNOWN)
type = VALUE;
else if (type != VALUE) {
ungetc(ch, stdin);
break;
}
buf[i++] = (char)ch;
}
else if (strchr(operators, ch)) {
if (type == UNKNOWN)
type = OPERATOR;
else {
ungetc(ch, stdin);
break;
}
/* Only allow single character operators for brevity */
buf[i++] = (char)ch;
break;
}
else {
if (type == UNKNOWN)
type = VARIABLE;
else if (type != VARIABLE) {
ungetc(ch, stdin);
break;
}
/* Use VARIABLE as a catch-all */
buf[i++] = (char)ch;
}
}
buf[i] = '\0';
return type;
}
int main(void)
{
char buf[BUFSIZ];
token_t type;
while ((type = next_token(buf, sizeof buf)) != UNKNOWN) {
switch (type) {
case VALUE: fputs("VALUE: ", stdout); break;
case OPERATOR: fputs("OPERATOR: ", stdout); break;
case VARIABLE: fputs("VARIABLE: ", stdout); break;
}
printf("'%s'\n", buf);
}
return 0;
}
My question is HOW?? When I closed the file then how it can be in use of some other process??
My gut reaction is to say that this is a timing issue, but it's possible that fclose() failed. First try testing the return value to see if there were any problems:
if (fclose(fp)) {
perror("Failed to close the file");
}
If fclose() succeeds then to check if it's a timing issue, where the OS is still holding onto the handle because flush and close requests are queued and haven't completed, you can try sleeping for a bit to give the OS time to catch up:
#include <stdbool.h>
#include <windows.h>
...
fclose(fp);
bool removed = false;
/* Try a few times with a pause inbetween */
for (int i = 0; i < 3; ++i) {
if (remove("filename.txt") == 0) {
removed = true;
break;
}
Sleep(200);
}
if (!removed) {
fputs("File was not deleted\n", stderr);
}
You may need to play with the pause amounts and number of attempts, but the above has worked well for me in catching any timing issues. 200ms is actually quite huge, and often far less than that works just fine.
The logic for sorting with string keys is no different than with numeric keys. The only difference is in the comparison, where with string keys you cannot use relational operators. Instead, compare with strcmp():
if (strcmp(a->name, b->name) < 0) {
/* a->name is lexicographically smaller than b->name */
...
}
This is as opposed to the numeric way of just comparing directly:
if (a->id < b->id) {
/* a->id is numerically smaller than b->id */
...
}
Other than that, your sorting algorithm shouldn't change unless you also move around the data (in which case some variation of strcpy() may be needed). But since you're already storing these records in structures, you can just copy the structure instances and all will be well.
You can have an identity column with autoincrement properties that isn't the primary key. In the new table, just create the new column, set it to identity "Yes", and with increment step and seed of 1.
i wonder what skyrim version you played guys? :D
PC is the only way, given the enormous modding community. ;)
James, you started with the sysadmin/IT tech route? I never knew that.
Yup. I always had an eye toward becoming a developer, but my first career path was on the IT side. In fact, I think that experience is very valuable in my current position because I consult with IT departments often. It's handy to be able to speak their language and actually know what I'm talking about. ;)
The comparison delegate returns an integer denoting the relation between the two objects: 0 for equal, -1 if x is "smaller", and +1 if x is "larger". So it would be more like this:
Private Function SortMyList(ByVal x As MyType, ByVal y As MyType) As Integer
Dim tsX As TimeSpan = x.dEnd.Subtract(x.dStart)
Dim tsY As TimeSpan = y.dEnd.Subtract(y.dStart)
If tsX < tsY Then
Return -1
ElseIf tsX > tsY Then
Return 1
Else
Return 0
End If
End Function
Assuming this is how you want to compare the timespans, of course.
hmmm~ just means the word can always be stay at the twinkling stage.
You're explaining what "twinkling" means by using the word "twinkling", do you not recognize how unhelpful this is? It's like saying that twinkling is when something twinkles. When we don't know the fuck what you mean by "twinkle", any use of "twinkle" in your explanation of "twinkling" is COMPLETELY MEANINGLESS.
just means the word can twinkling when we run the programm.
Not informative. Describe exactly what you want to see happen, please. Obviously "twinkling" isn't a meaningful descriptive term, so using it in a recursive definition is nonsensical.
What do you mean by "twinkling" motion?
A static member is shared between all objects of the class whereas each object of the class contains a copy of the instance member. It's really as simple as that, though the static
keyword is heavily used for different purposes in C++.
Using %ls correctly printed the wchar_t to file: fprintf(logptr,"%ls\n",section->name);
Yes, you're correct. I forgot that fwprintf() doesn't default to wide orientation for %s. My bad.
I'm afraid it doesn't work. :(
Pname
will not work. That's a given, so remove that variable entirely; you can't expect it to represent a wide string. Does your log file still contain just "A" when you use fwprintf() to write section->name
?
If char
could represent the same thing as wchar_t
then there wouldn't be two different types of characters. You have a wide string, and thus you need to either convert it to a narrow string iff you're sure that the narrow string can represent it, or properly display the wide string as a wide string:
fwprintf(fp, L"%s\n", str);
argv[0] is always the program name.
Not always. If argc is greater than zero, argv[0] is allowed to be an empty string, should the program name not be available for some reason. Even if argv[0] isn't an empty string, the format of the "program name" is implementation dependent. It's generally a safe assumption to expect either just the file name of the executable or the full path, but that's still an assumption.
Each other index is the characters up to a white space.
The command line interpreter will handle quoted strings that have embedded whitespace (assuming such a thing is supported by the system), so the "up to a whitespace" part isn't entirely accurate. For example, take this program:
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; ++i)
printf("'%s'\n", argv[i]);
return 0;
}
If the command line contains $prog.exe this "is a" test
, the output will be something along the lines of
'prog.exe'
'this'
'is a'
'test'
Also, don't forget that argv[argv] is guaranteed to be NULL, even if argc is 0. So on top of having a count of arguments in the form of argc, you also have a sentinel value at the end of argv if argc is not available for some reason (like argv being passed to a function) or pointer arithmetic over the argv array is faster than indexing on your system.
Is this a question about the DateTimePicker or about MySQL? If it's the former then the control has a Value property that gives you the stored DateTime object. You can then get the long format as a string and save it to MySQL:
Dim longdate As String = dateTimePicker1.Value.ToLongDateString()
' Save longdate to MySQL