6,741 Posted Topics
Re: Put it in your gcc invocation: [code=text] all: run test: test.c gcc -D HELLO test.c -o test run: test ./test clean: rm *~ *.o test [/code] | |
Re: Clearly you didn't search the forums before asking this question, because it's very common. You need to add a pause at the end of the program because the IDE allocates a console window for it to run. When the program ends, the window is destroyed and closes. The Dev-C++ code … | |
Re: [QUOTE]which is the one you use?[/QUOTE] I use several, though my favorite is Visual Studio. If only it weren't so damn slow and resource hungry. | |
Re: Have you tried prepending a '0' to the string before converting it? | |
Re: [QUOTE=charlybones;1583304]Also, you *might* want to do [CODE]fflush(stdin);[/CODE] right before every single "scanf" that you have. Regards.[/QUOTE] You might, if you want to suffer from [URL="http://www.eskimo.com/~scs/readings/undef.950311.html"]undefined behavior[/URL]. fflush is not defined for input streams and is the incorrect way of discarding unextracted input. The correct way is a loop: [code] void … | |
Re: [QUOTE]i want to know, what kind of addresses do pointers deal with?[/QUOTE] That's not specified. [QUOTE]and how can i access a particular memory area using pointers?[/QUOTE] It's not portable, but traditionally that's been done by something like this: [code] /* Point to address 0x12345678 and treat it as an int … | |
Re: So you want to print an unknown, variable range of numbers, without using any form of loop or recursion. Pretty much any solution with those restrictions will rely on a hidden loop or recursion at a deeper level. It becomes a question of semantics: "Is this enough of a loop … | |
Re: This isn't directly relevant, but have you tried not using Turbo C? It has limitations that will be terribly frustrating on modern hardware. | |
Re: I suspect what you want are [URL="http://msdn.microsoft.com/en-us/library/tk67c2t8(v=VS.100).aspx"]property attributes[/URL] that affect how the property is displayed in a property grid control. If your class is more than just a design-time component, you can also make use of the [URL="http://msdn.microsoft.com/en-us/library/aa302326.aspx"]PropertyGrid control[/URL] directly in your own applications. | |
Re: You open the file for writing on each iteration. This truncates it to zero length before writing. Try opening the file before the loop and leaving it open until after the loop completes. | |
Re: *sigh* Here's a correct and portable program that does what r0shi and possibly the OP wanted: [code] #include <stdio.h> #include <stddef.h> int main(void) { int a[2]; // Guarantee that the addresses exist int *p = a; int *q = p++; // Casting to char* to get a byte count ptrdiff_t … | |
Re: Presumably you're using a vector of std::string. The fstream constructors don't have an overload for std::string, so you need to call c_str(): [code] ifstream file(files[0].c_str()); [/code] | |
Re: I see you didn't read our rules or the stickies. Specifically, we don't give homework help without some evidence that you've made an honest attempt to do it yourself. | |
Re: The %d specifier prints a signed int. If you want to print an unsigned value, use %u. Also, you'd be better off using INT_MIN, INT_MAX, and UINT_MAX from limits.h. That'll protect you from the off-by-one trap that you fell into with 4294967296. | |
Re: [QUOTE]And do you need any more information or is this snippet sufficient to guess correctly?[/QUOTE] The correct answer is "send the code back to the author with a bug report". Copying bytes into an int punned as char* is only safe when the bytes being copied were acquired from another … | |
Re: [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1048384015&id=1043284392"]Clicky[/URL]. | |
Re: EOF isn't a character, it's a flag returned by getchar denoting end-of-file. You can signal end-of-file from the command prompt (assuming Windows) with the Ctrl+Z keyboard combination. If you want to print the value of EOF, I'd suggest using printf: [code] printf("EOF: %d\n", EOF); [/code] | |
Re: [QUOTE]I just read in K&R that a function, even if not defined as void, need not return a value.[/QUOTE] What page? From memory, the only place where K&R makes such a grievous mistake is in the beginning tutorial with the initial definitions of main. However, that's a pedagogical decision that … | |
Re: [QUOTE]Is there a difference between programming and scripting?[/QUOTE] This question cannot be answered until you clearly define what you mean by "programming" and "scripting". | |
Re: [QUOTE=Luckychap;607133]I think the node structure should be like this: [CODE] struct node { void *data; int type; struct node *next; struct node *prev; }LINK; [/CODE] where: [B]type[/B] is used for type. For example type=1 indicates int, type=2 indicates float, type=3 indicates userdefine and so on... and Insert function will look … ![]() | |
Re: [QUOTE]But it's C i cant make it to work with C++[/QUOTE] Be more specific. Why doesn't it work with C++? Are you getting compilation errors? Runtime errors? | |
Re: [QUOTE]What is the scope of the exception variables when I catch them by reference.[/QUOTE] I think you mean what is the [i]lifetime[/i] of exception objects. Because the scope is a trivial question: the scope of an exception variable, whether caught by value, pointer, or reference, is the catch block. The … | |
Re: Please post a complete program that exhibits the problem. | |
Re: [QUOTE]I know C++ well and have written some programs in it but when I look at a program's code,I can't understand it.[/QUOTE] There's a difference between knowing C++ and knowing how to program in C++. "Real world" programming involves more than just the language. There needs to be an understanding … | |
Re: [QUOTE]int *ptr=50;[/QUOTE] This is attempting to point [ICODE]ptr[/ICODE] to address 50. Typically, you can only point to addresses within your process' address space, otherwise you'll get a segmentation fault. Java references are actually gimped pointers, which should give you an idea of how to use C pointers for basic object … | |
Re: When it comes to being mods, I think we're all losers. But our loss is Daniweb's gain. ;) [QUOTE]Winner gets to delete all spam in the marketing forums for six months.[/QUOTE] That's easy, just delete all new posts every time you log in. :D | |
Re: [QUOTE]I have used calloc(), instead of combination of malloc and memset as a work around.[/QUOTE] calloc is the functional equivalent of malloc + memset. It might be faster due to the potential for standard library optimization over hand rolled code, but probably not enough to make a big difference. Have … | |
Re: [QUOTE]the problem is in this part, in case u can't find it in the code above[/QUOTE] So are the preceding 1500 lines relevant or not? | |
Re: [QUOTE]mayb the problem is when you still have to work on next program, so with return 0 it will end current program and start the next? but with system("exit") it will totally close it?[/QUOTE] That's an impressive feat of misplaced logic. No, you were correct in saying that [iCODE]system("exit")[/iCODE] is … | |
Re: You need a way to point back to the [ICODE]coms[/ICODE] index after sorting [ICODE]table[/ICODE]. Rather than a sorted array, I'd go with a map: [code] void standings(userClub uc){ map<int, int> table; for(int i=0; i<9; i++){ table[coms[i].pts] = i; } table[uc.pts]=9; map<int, int>::const_iterator it = table.begin(); map<int, int>::const_iterator end = table.end(); … | |
Re: [QUOTE]you should always use the int main(int nargs, args[]);, it is better then just int main()[/QUOTE] Please explain why it's better. | |
Re: I think you need to go back to your teacher and get some details. Asking you to create a compiler, regardless of size, in an intro to programming course is a little excessive. | |
Re: Really? You've found nothing on the web? | |
Re: You're doubling the direction test. [ICODE]x[/ICODE] or [ICODE]y[/ICODE] is already adjusted in the call to movePlayer, and you further adjust it when setting [ICODE]ch[/ICODE] in movePlayer. One possible fix is removing the switch in movePlayer and just setting [ICODE]ch[/ICODE] to [ICODE]map[x][y][/ICODE] in all cases. | |
Re: [QUOTE]I know the getch() is old and non-standard, but cin.get() does not work for me in some situations, so I thought I should mention getch() .[/QUOTE] What situations? Using an input block to pause the program really only gets hampered by one thing: a non-empty stream. getch() always works because … | |
Re: Until you know the rules for braces, it's best to always use them: [code] if (secretnum<getint) { cout<<"try a lower number"; goto loop; } else if (secretnum>getint) { cout<<"try a higher number"; goto loop; } else { cout<<"that is correct"; } [/code] By the way, you should also avoid goto … | |
Re: [QUOTE]All POST operations are performed at the end of a statement, and all PRE operations are performed at the beginning of a statement. Is that correct?[/QUOTE] It's close enough, yes. To be strictly precise, the update can happen any time between the previous and next sequence point as long as … | |
Re: [QUOTE]I need to add this to the output statement?[/QUOTE] SetColors needs to be called with appropriate arguments before the output you want with a different color. It's also not a bad idea to save the current color attributes and restore them when you're done. That's pretty trivial with a sentry … | |
Re: Those weird symbols mean you haven't terminated your strings with '\0'. | |
Re: [QUOTE]Who do you think this guy is?[/QUOTE] What makes you think he's anything other than a model hired for that photo? | |
Re: Project properties? | |
Re: [B]>if(chooseType == "a" || "A"){[/B] C++ parses it like this: [code] if(chooseType == "a" || "A" != 0){ [/code] Adjust accordingly. | |
Re: [QUOTE]So is the compiler not good?[/QUOTE] The compiler that ships with Visual C++ is quite good. Your problem is very vague, but I suspect you're trying to use non-portable stuff. Can you give an example of what code "is not working"? | |
Re: For the record, hiding a pointer behind a typedef is a fantastic way to confuse both yourself and others. | |
Re: I'll save you the trouble of searching around: [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/"]qsort[/URL]. | |
![]() | Re: To answer the question in your title, yes. write's first argument must be a pointer to char where the number of available characters starting at that pointer match the second argument. [QUOTE]everything between these values became null.[/QUOTE] Can you elaborate? What do you want to happen (with examples) and what's … ![]() |
Re: [QUOTE]Do you know what could be the issue?[/QUOTE] Yes, the issue is you not understanding how substr works. The second argument is a count, not an index. | |
Re: [QUOTE]But shouldn't I clear out the input stream before I use cin again?[/QUOTE] How do you know that it needs to be cleared? What if the next request for input corresponds to whatever is already in the stream? I can type "123 4.5 booga" all on one line and the … | |
Re: Assuming your matrix is a two dimensional array, and the function takes a one dimensional array of the same type, you can do this: [code] some_function(my_matrix[3]); [/code] I'm assuming a lot because you didn't provide nearly enough information to properly answer the question. |
The End.