2,384 Posted Topics
Re: [url]http://c-faq.com/aryptr/ary2dfunc3.html[/url] [url]http://c-faq.com/aryptr/index.html[/url] | |
Re: Maybe the answer to the interview question is that none is faster than any other? Or that the answer is outside of C itself? | |
Re: Make the string separately using sprintf or the like. [edit]Make sure your destination has enough room for the text you want in it. | |
Re: [CODE]#include <iostream> using std::cout; using std::hex; #include <string> using std::string; #include <sstream> using std::ostringstream; #define VERSION_MAJOR 1 #define VERSION_MINOR 1 #define VERSION_PATCH 2 #define VERSION ((VERSION_MAJOR << 16) | (VERSION_MINOR << 8) | VERSION_PATCH) int main() { int version = VERSION; cout << "version = " << hex << version … | |
Re: [QUOTE=cscgal;1075897]Well then be more vocal about which features you use and how you use them. :)[/QUOTE] It's hard to read your mind about what you're going to get rid of next. :icon_wink: [QUOTE=cscgal;1075897] i.e. When you first visit DaniWeb, how do you begin your visit?[/QUOTE] UserCP, which used to give … | |
This is a [inlinecode]strtol[/inlinecode] version of [url=http://www.daniweb.com/code/snippet353.html] Read an Integer from the User, Part 2[/url]. | |
Re: [CODE] do { fputs("Enter an integer[COLOR="Red"] (0-100)[/COLOR]: ", stdout); fflush(stdout); } while ( !mygeti(&value)[COLOR="red"] || value < 0 || value > 100[/COLOR] );[/CODE] | |
Re: Quantity is not always the best criteria for evaluating sources of information. You might also want to consider: [url]http://cboard.cprogramming.com/[/url] Not a forum, per se, but I'd also throw in this (an excellent resource for searching): [url]http://groups.google.com/group/comp.lang.c++/topics[/url] | |
Re: [QUOTE=MAV_DevWantaB;1082924]I believe it is working correctly but I think I have my Understanding of bits backWards....... :hair: [/QUOTE] When you print the bits of the number, I would presume you want to print MSB to LSB so it reads from left to right. By printing from LSB to MSB, it … | |
Re: [QUOTE=Happy Family;1083111]Hi every one. it is my solution. if it is false, reply. using Turbo C[/QUOTE]Pretty ugly, and it doesn't need to be nonstandard. Was this an assignment to do this without using the standard library? | |
Re: Line 42? How about posting a small but compilable snippet that demonstrates the problem? | |
Re: [QUOTE=The-IT;1082808]I created a script that uses a variable in a for-loop, that was defined before the loop its self. I get this error: [code]skilz.c: In function ‘main’: skilz.c:16: [COLOR="Red"]error: ‘prog’ undeclared [/COLOR](first use in this function) skilz.c:16: error: (Each undeclared identifier is reported only once skilz.c:16: error: for each function … | |
Re: In the first one, you respond [iCODE][COLOR="Red"][I]name[/I]\n[/COLOR][/iCODE] (where the [iCODE]\n[/iCODE] is the result of pressing the [enter] key. The [ICODE]%s[/ICODE] with [ICODE]scanf[/ICODE] stops at whitespace, which [iCODE]\n[/iCODE] is, so that is leftover in the input buffer. This will immediately satisfy the subsequent call to [ICODE]getchar[/ICODE]. Since [ICODE]getchar[/ICODE] returns an [ICODE]int[/ICODE], … | |
Re: [url]http://c-faq.com/varargs/index.html[/url] [url]http://c-faq.com/varargs/vprintf.html[/url] [url]http://c-faq.com/varargs/handoff.html[/url] | |
Re: I don't know that you've found your answer yet:[code]#include <iostream> using namespace std; class myclass { public: myclass() { cout << "Hi, I'm the constuctor" << endl; } }; int main() { myclass *m; m = (myclass*) malloc (sizeof(myclass)); [COLOR="Red"]m = &(myclass());[/COLOR] return 0; }[/code][QUOTE]main.cpp:Error 50: Attempted to take the … | |
Re: [url]http://parashift.com/c++-faq-lite/assignment-operators.html[/url] | |
Re: [QUOTE=s8498;1079764]I still can't figure out how to read 24 lines at a time :( Or where I should put the if statement and what that would do and how to link it all together? *** Oh, I also need to figure out how to number each line of the text … | |
Re: A union initializer pertains to the first named member. | |
Re: Just do the "subscripting" "by hand". | |
Re: And is [url]http://www.daniweb.com/forums/thread245380.html[/url] related? | |
Re: Why do you cast away the constness? [code]char * filePathName = (char *)(filePathNameString.c_str()); TAQTradesReader taq( filePathName );[/code] Surely you are making no attempt to modify the text that you are passing? | |
Re: [QUOTE=dennis.d.elston;1078879]I am trying to write a funtion that will return the value of 1 if its string argument is a palindrome. I have started but am unsure if it is correct. Could someone please take a look and point me in the right direction? Thanks [CODE]#include <string.h> Int palindrome (const … | |
Re: If it's a text file, and apparently PPM is [edit][URL="http://en.wikipedia.org/wiki/Portable_pixmap"]or is it?[/URL][/edit], don't mess with binary mode. Also, don't write "little integers" that happen to be characters as characters -- that is, don't use fputc; write these little integers as integers using *printf and read with *scanf. | |
Re: [QUOTE=Derp2000;1078499]Thank you very much. :) I'm having a problem where it ignores the fgets in the first loop iteration but I finally feel like I'm getting somewhere with this.[/QUOTE] That's because you didn't clean up after this: [CODE]scanf("%i", &numNames);[/CODE] The newline is left over. | |
Re: [QUOTE=progag;1078662]can anyone write the full program ?[/QUOTE]You're supposed to show an attempt, and corrections and suggestions would then be offered. [QUOTE=progag;1078679]11 ERRORS[/QUOTE]How rude. You make no attempt and then complain about a gift? Why don't you take a pop at correcting the errors and start trying to do your own … | |
Re: [QUOTE=Ancient Dragon;1076607]I assume she has a lot of other higher priority things to do than devote a lot of time/effort to something like this.[/QUOTE] [url]http://www.daniweb.com/twitter/tweet246053.html[/url] :icon_razz: ![]() | |
Re: 1. What is your favorite IDE [B]SlickEdit[/B] 2. What is your favorite GUI library [B]N/A, OpenGL if it weren't N/A[/B] 3. What is library that you often use? [B]Standard libraries; libXML, zlib, dabbling in libCurl in a far lesser extent[/B] 4. Anything related? [B]I recommend using Lint[/B] | |
![]() | Re: To change the value of an object in a called function, you generally pass a pointer to the object. [CODE]#include <stdio.h> #include <stdlib.h> void allocate_matrix([COLOR="Red"]int ***[/COLOR]table, int rows, int columns); int main() { [COLOR="Green"]int i, j;[/COLOR] int **table = NULL; allocate_matrix([COLOR="Red"]&[/COLOR]table, 3, 3); [COLOR="Green"]for ( i = 0; i < … ![]() |
Re: [QUOTE=evstevemd;1076283]I see alot of libraries written in C and I like C++ OOP way. How can I use a given C library functions in C++?[/QUOTE] [url]http://parashift.com/c++-faq-lite/mixing-c-and-cpp.html[/url] | |
Re: [QUOTE=xavier666;1070819]And can you provide me a link where I can find the problems associated with [icode]scanf()[/icode][/quote] [url]http://www.c-faq.com/stdio/scanfhang.html[/url] [url]http://www.c-faq.com/stdio/scanfinterlace.html[/url] [url]http://www.c-faq.com/stdio/scanfc.html[/url] [url]http://www.c-faq.com/stdio/scanfjam.html[/url] [url]http://www.c-faq.com/stdio/scanfprobs.html[/url] [QUOTE=xavier666;1070819]and [icode]fflush()[/icode][/QUOTE] [url]http://www.c-faq.com/stdio/stdinflush.html[/url] [url]http://www.c-faq.com/stdio/stdinflush2.html[/url] ;) | |
I didn't notice until recently that another post of mine got munched by the latest "upgrade". In [URL="http://www.daniweb.com/tutorials/tutorial45806.html"]this[/URL], I'd had a link in the comments of the code. Oh, it was once simple and dandy looking, but now it has some pre-processing done on it and looks like crap. Since … | |
Re: I would definitely think about rewriting that ... thing ... using arrays. But here: [CODE]double computation([COLOR="Red"]matrix [/COLOR]k, int mA, int nA, int [COLOR="Red"]matrix[/COLOR], int m1, int m2, int m3, int m4, int m5, int m6, int m7, int m8, int m9, int m10, int n1,int n2,int n3,int n4,int n5,int n6,int … | |
Re: Your attempt at reading the data from the file needs a lot of work. You're only trying to read the id and the grades, for example, but you pretend as if you've read the names. Also, you need to learn how to index arrays. | |
Re: Using gcc? [CODE]gcc -E main.cpp[/CODE] [edit]Some code... [CODE]#include <stdio.h> #define SetMacro(name,type) \ virtual void Set##name (type _arg) SetMacro(foo,int) { } int main() { return 0; }[/CODE] gcc's output: [CODE]... virtual void Setfoo (int _arg) { } int main() { return 0; }[/CODE] | |
Re: [url]http://www.daniweb.com/tutorials/tutorial45806.html[/url] | |
Re: You can't do this in the declaration: [CODE]const double PI = 3.1416;[/CODE] Initialize PI in the constructor... [CODE]class Circle { private: double radius; const double PI; public: Circle(double rad = 0) : radius(rad), PI(3.1416) { } // ...[/CODE]Or make it static... [code]{ private: double radius; [COLOR="Red"]static const double PI;[/COLOR] public: … | |
Re: [QUOTE=~s.o.s~;1073428]IMO the main problem I think is with the way the questions are phrased. People tend to post their entire mind dump when asking questions which presents a difficulty to those trying to answer the questions. I've seen countless questions narrating the entire use case [i need to create a … | |
In [URL="http://www.daniweb.com/forums/post1071291.html#post1071291"]another post[/URL] I found the following construct: [CODE]#define STATIC_ASSERT(condition) \ do \ char foo[condition] = {0}; \ while ( false );[/CODE] First, I had to do a [URL="http://clusty.com/search?query=static%20assert%20compile%20time"]search[/URL] to see whether "static" meant "compile-time" here (that poor keyword [I]static[/I], it's got too many overloaded meanings in C and C++). … | |
Re: Or change the scope of [ICODE]i[/ICODE]. Remember to return a value. And to initialize sum. [CODE]float getAverageGrade (float grades[], int count) { float sum [COLOR="Red"]= 0[/COLOR]; float average; [COLOR="Green"]int i;[/COLOR] for (i=0; i<count; i++) { sum += grades[i]; } average=sum/i; //I have tried this in the loop and in a … | |
Re: [url]http://web.archive.org/web/20080618001558/c-faq.com/bool/bool2.html[/url] | |
Re: The result of the [ICODE]||[/ICODE] operator will be either 0 or 1. Let's walk through this: [code]if ( 1 == ([COLOR="Red"]2 || 2[/COLOR] || 2) )[/code] [code]if ( 1 == ([COLOR="Red"]1 || 2[/COLOR]) )[/code] [code]if ( [COLOR="Red"]1 == 1[/COLOR] )[/code] [code]if ( 1 )[/code] So your condition is always true. … | |
Re: When there are compiler errors, you get no .exe. You need to fix the errors before the program will be created; once an .exe is build you can run it. You're trying to compare an int to a structure: [code]//structure for dimension typedef struct{ mNum **pX;//declares double pointer for matrix … | |
Re: [QUOTE=tgreiner;1070551]I am having a problem with overloading an operator within a class structure. Below is the program that illustrates my problem. It defines a class Matrix, creates two matrices and multiplies them. I created to multiplication functions. The first is a straight function, the second uses the overloaded * operator. … | |
Re: [QUOTE=simonfoley;1071736]Got gets() from my tutor! It was part of a lesson on string handling.[/QUOTE]Oh, my. Don't expect to learn C or C++ in the course you are taking. [url=http://www.daniweb.com/tutorials/tutorial71858.html]User Input: Strings and Numbers [C++][/url] [url=http://www.daniweb.com/tutorials/tutorial45806.html]User Input: Strings and Numbers [C][/url] | |
Re: [QUOTE=new programer;1070558]are you suggesting this ? [CODE]string concat(const char* title, const char* first_name, const char* last_name, int l1, int l2, int l3) { string full_name; for(int i=0; i< l1; i++) full_name = title[i]; for(int i=0; i<l2; i++) full_name = [COLOR="Red"]full_name + [/COLOR]first_name[i]; for(int i=0; i<l3; i++) full_name = [COLOR="Red"]full_name + … | |
Re: I only skimmed your question, but it sounded like: [url]http://parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] [edit]Short fix? [CODE]//Main.cpp #include <stdio.h> #include <string.h> #include "CClient.h" #include "TArray.[COLOR="Red"]cpp[/COLOR]" [/CODE] | |
Re: [CODE]#include <stdio.h> int main() { const char filename[] = "file.txt"; FILE *file = fopen(filename, "r"); if ( file ) { char line[BUFSIZ], text[10]; [COLOR="Red"]while ( fgets(line, sizeof line, file) )[/COLOR] { [COLOR="Red"]if ( sscanf(line, "%9[^, .]", text) == 1 )[/COLOR] { printf("text = \"%s\"\n", text); } } } return 0; … | |
Re: Are you sure you've got the correct [URL="http://en.wikipedia.org/wiki/Body_mass_index"]formula[/URL]? Checking the return value from scanf is a good idea. [code]#include <stdio.h> int main(void) { float height, weight, bmi; /* * Get user input. */ for ( ;; ) { int ch; printf("Enter your height in inches and weight in pounds: "); … | |
Re: [QUOTE=bonotevo;1069425]This is my first post so please bear with me. I am bringing in 2 files into 2 arrays and then trying co compare the arrays to each other. When I compare the arrays, I am trying to find out how many locations have matching letters in both strings. ) … |
The End.