2,384 Posted Topics
| |
Re: [QUOTE=Chainsaw]That can show up if you have, say, a file name in a string and you forget to double escape the slash: "C:\Chainsaw\Kelp" // wrong "C:\\Chainsaw\\Kelp" // right[/QUOTE]Or [url=http://groups-beta.google.com/group/comp.lang.c/msg/9d3ac81f37b60ca9]use forward slashes[/url]. | |
Re: Now that's an impressive list of errors! Since there is no code to look at, my guess would be a missing semicolon. For example, the following will make a similar mess.[code]int x #include <stdio.h>[/code] | |
Re: [QUOTE=odee]should i use [COLOR=Green]#define[/COLOR] or [COLOR=Black]const[/COLOR] in declaring constant variables?? which one is better? when should i use [COLOR=Green]#define[/COLOR] or [COLOR=Black]const[/COLOR]? for example when i declare a hexadecimal (0x01), should i use [COLOR=Green]#define [/COLOR]or [COLOR=Black]const[/COLOR]?[/QUOTE]It depends. A constant variable will take up space, and finding its value may take more … | |
Re: Try this:[code][COLOR=Green]int [/COLOR]main() { // EventPtr event_queue; Event *eventPtr; eventPtr = new Event[MAX_EVENTS]; [COLOR=Indigo]eventPtr[/COLOR][0][COLOR=Blue].[/COLOR]event_type = 1; [COLOR=Indigo]eventPtr[/COLOR][0][COLOR=Blue].[/COLOR]time_value = 2; [COLOR=Indigo]eventPtr[/COLOR][0][COLOR=Blue].[/COLOR]bus_num = 0; [COLOR=Indigo]eventPtr[/COLOR][0][COLOR=Blue].[/COLOR]bus_stop = 1; [COLOR=Green]return 0;[/COLOR] }[/code] | |
Re: [QUOTE=murschech]For starters, you'll need 2 constructors. One will be something like [code]rational(int m, int n) { num = m; den = n; //You really should check for n == 0 }[/code]and the other (the default) would be[code]rational() { num = 0; den = 1; }[/code][/QUOTE]This could also be done like … | |
Re: >How would I find the highest salary salesperson of a list of salespersons The same way you find the largest value in an array. | |
Re: Read the input as a string and parse it into hours, minutes, whatever. | |
Re: [code]char Fraction::slash=[COLOR=Red]"[/COLOR]/[COLOR=Red]"[/COLOR];[/code]This should be:[code]char Fraction::slash=[COLOR=Blue]'[/COLOR]/[COLOR=Blue]'[/COLOR];[/code] | |
Re: [QUOTE]I am having a problem getting the execution screen to stay in order for me to view the program. Can someone tell me what is wrong with my program please?[/QUOTE] Nothing is "wrong". [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043803465&id=1043284385"]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043803465&id=1043284385[/url] | |
Re: [quote]I have to write a program to read N data items into two arrays, X and Y, of size 25.[/quote]Surely you can translate that into code.[code]int X[25]; int Y[25];[/code][quote]Calculate and store the products of corresponding pairs of elements of X and Y in a third array, Z, also of size … | |
Re: Being a math major, you probably don't need to be told that the average will be the [FONT=Courier New][I]sum[/I][/FONT] divided by the [FONT=Courier New][I]count[/I][/FONT]. [Heavy hinting for possible variable names here.] Entering a single number might be done like this.[code] int number; cout << "Enter a number: "; cin >> … | |
Re: [QUOTE=seeplusplus]i have a problem with this code, my cin statement is only reading in one character i think, how do i fix this?[/QUOTE]Don't ask it to read only one character. (And read some of the other responses above.) (And please make an attempt at a fix!) (And please learn to … | |
Re: Dividing by zero?[code]if ( ([COLOR=Blue]A=0[/COLOR])||(((B*B-4*A*C))<=0) );[/code]This assigns 0 to A. Doesn't your compiler give you a warning? | |
Re: How would you express the addition of two complex numbers without code? Then try to translate that into code. (And keep in mind what you intend to do: add to the current object, or add two distinct objects and return a third.) [And you can edit your post to add … | |
Re: [QUOTE=vegaseat]Test drive this to get another hint: [php]// pad with zero using sprintf() #include <stdio.h> int main() { int mile; //, foot, inch; char *pad; printf("Enter miles: "); scanf("%d", &mile); fflush(stdin); // flush input stream // pad with max 3 zeros (this is a zero not an ohh) sprintf(pad,"%03d",num); printf("Zero … | |
Re: Your editor appears to have used [COLOR=Red]“[/COLOR]fancy[COLOR=Red] | |
Re: [QUOTE=Acidburn]abs function is for doubles...fabs is for floats[/QUOTE]No. Care to try again? | |
Re: Yes, you are trying to write to read-only memory. Create an array with enough space instead of trying to write to a string literal initializer. [edit][code]#include <stdio.h> #include <string.h> int main( void ) { char user[] = "name"; char temp[ sizeof user + 5 ] = "USER "; strcat(temp, user); … | |
Re: Perhaps something like this: [url]http://www.eskimo.com/~scs/C-faq/q14.5.html[/url] [code]#include <stdio.h> #include <math.h> int main(void) { float a = 1.0F, epsilon = 1.19209e-07F; while ( (float)fabs(a) > epsilon ) { printf("a = %g\n", a); a /= 2.0f; } return 0; } /* my output a = 1 a = 0.5 a = 0.25 a … | |
Re: [code] char* value; [/code]Where is the part that you have this pointer point to memory you can write to?[code] value += int(passkey[x]); [/code]Can you describe in words what you believe this is doing?[code] num_value = atol (value); [/code]Since [FONT=Courier New]atol[/FONT] requires a null-terminated string, where do you null terminate the … ![]() | |
Re: [QUOTE=murschech]My question was what are the first two lines about. I was told that their purpose was to avoid mutiple compilations.[/QUOTE]Perhaps you remember it wrong -- was it to "[post=81677]prevent multiple [I]inclusion[/I][/post]"? | |
Re: Would some adaptations of [url=http://www.daniweb.com/code/snippet149.html]this[/url] be helpful?[code]#include <stdio.h> #include <limits.h> char *bits_uchar ( char *dest, unsigned char value ) { char *start = dest; unsigned char bit; for ( bit = 1 << (CHAR_BIT - 1); bit > 0; bit >>= 1 ) { *dest++ = value & bit ? … | |
Re: Promote one of the operands to [FONT=Courier New]double[/FONT].[code] int a = 9, b = 12; double d = [COLOR=Blue](double)[/COLOR]a / b;[/code] | |
Re: This string is 7 characters long (it ends with a null terminator):[code]".-..-."[/code]By declaring the second dimension the wrong size, your string has no null terminator and consectutive strings run together. | |
Re: Care to tell us what [FONT=Courier New]itemType[/FONT] is? Compiling eyes want to know. | |
Re: [code]/* triangle.h */ #ifndef TRIANGLE_H #define TRIANGLE_H struct triangle { double base, height; }; #endif[/code] | |
Re: Try something along this line:[code]#include <fstream> #include <cstdio> using namespace std; int main() { char filename [ FILENAME_MAX ]; for ( int i = 1; i <= 5; ++i ) { [COLOR=Blue]sprintf(filename, "%d.txt", i);[/COLOR] ifstream file(filename); // ... } return 0; }[/code] | |
Re: [QUOTE=compeat]hi! I have a problem about "[B]range of data types[/B] ".I work on program that require long digits .in "boland c++ 5.2 's help" range of long is [B]4294967295[/B] . but why this sample program doesn't work??!! [CODE] int main(){ long a=4294967295,b; b=a; return 0; }[/CODE] CAN YOU HELP ME? … | |
Re: [QUOTE=mr_mooz]So how can I get round that? when i use just & or | i get an error.[/QUOTE]You want to bitwise AND or bitwise OR two floating point values? The result may not be a number even if you were able to combine the bits of each object. | |
Re: [QUOTE=sid3ways s13]I'm on my second assignment now which I have to write a program that will ask the user for one of three choices. for example: Press c to calculate the area of a circle, t for a triangle, r for a rectangle, or q for quit. Then the program … | |
Re: [QUOTE=seeplusplus]alright, say i enter a 1,2,3 when my program asks me, when im printing out the contents of the pointers in the function order_chars, it prints 1,2,1....instead it should print 3,2,1....cause the function reorders the characters i entered around. heres my code, can you see the problem?[/QUOTE][code]order_chars ( c3ptr, c2ptr, … | |
Re: Only return [FONT=Courier New]ptr[/FONT] from the function. Only [FONT=Courier New]strcpy[/FONT] a valid string to [FONT=Courier New]ptr[/FONT] (if it is non-[FONT=Courier New]NULL[/FONT]). | |
Re: The [B][FONT=Courier New]break;[/FONT][/B] will only break the innermost loop.[code]#include <iostream> #include <cstddef> using namespace std; int main ( void ) { int array [ 10 ]; size_t i, j; for ( i = 0; i < sizeof array / sizeof *array; ++i ) { cout << "? "; cin >> … | |
Re: It is likely that you should be using the standard header [FONT=Courier New]<stdlib.h>[/FONT]. | |
Re: [url]http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.8[/url] [thread]16201[/thread] | |
| |
Re: [URL=http://www.google.com/search?q=free+c%23%2Fc%2B%2B compiler]Google[/URL] or [url]http://www.compilers.net/[/url] come to mind. | |
Re: [code]#include <stdlib.h>[/code] | |
Re: [QUOTE=blackhawk]There is no support for the inport and outport functions in borland C++ win32. Are there any alternative functions avaliable.[/QUOTE]You may want to check out WinIO, which can be found [url=http://www.internals.com/]here[/url]. | |
Re: Please read the [url=http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2]Announcement[/url]. | |
Re: [QUOTE=zack_rage]when i run or compile basic programs that i have made it says a error message the stdio.h is not found so that the program has no output [/QUOTE]It sounds like you haven't told the compiler where to find the headers. [QUOTE=zack_rage]any good compilers that can you recommend or tips … | |
Re: Exactly 1 [FONT=Courier New]delete[/FONT] for every [FONT=Courier New]new[/FONT]?[code]struct movies { char title[10]; int year; }; int main() { movies *films = new movies; // use films delete films; return 0; }[/code]Or [I]don't[/I] use [FONT=Courier New]delete[/FONT] and don't use [FONT=Courier New]new[/FONT]?[code]struct movies { char title[10]; int year; }; int main() { … | |
Re: Is this what you are asking? [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044654269&id=1043284392[/url] | |
Re: [QUOTE=galmca]i have tried everything[/QUOTE]But you forgot to copy and paste these attempts that we may correct them and instead assume that someone will drop in your lap exactly the code you are thinking of. | |
Re: Neither. An array of [FONT=Courier New]char[/FONT] that ends with a terminating null byte is a c-style string. A single char thus can never be a string. And an uninitialized [FONT=Courier New]char data[];[/FONT] is an incomplete type. And [FONT=Courier New]'operator<<' not implemented in type 'istream' for arguments of type 'char *'[/FONT]. | |
Re: Worthwhile reading:[list][*][url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043372399&id=1043284385[/url] [*][url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044652485&id=1043284385[/url][/list] | |
Re: From a quick glance, I'd guess it might be related to the missing breaks for each case. Would you mind describing the error? | |
Re: It prevents multiple inclusion of the header. That is, on a second attempt to [FONT=Courier New]#include "add.h"[/FONT], [FONT=Courier New]ADD_H[/FONT] would already be defined and thus the entire [FONT=Courier New]#ifndef[/FONT] block would be skipped. | |
Re: Try compiling and running the code you are developing.[code]#include<[COLOR=Red]iostream[/COLOR]> [COLOR=Red]using namespace std;[/COLOR] void my_sum(int r) { float sum; sum = 2 * 3.14 * r; cout << "The circumference of a circle is " << sum << "." << endl; } int main() { [COLOR=Red]my_sum(1); return 0; }[/COLOR][/code] |
The End.