2,384 Posted Topics
Re: [QUOTE=vivekgalatage]can anyone please explain me about the concept of namespaces?[/QUOTE]Doing a [url="http://www.google.com/search?q=%22C%2B%2B+namespaces%22"]search[/url] is your best bet for general queries. | |
Re: An object is not just a C++ thing associated with a class.[QUOTE][font=Times New Roman][size=3][b]object[/b] region of data storage in the execution environment, the contents of which can represent values[/size][/font][/QUOTE]So [font=Courier New]int[/font]s and pointers and arrays are objects too. | |
Re: [url="http://users.powernet.co.uk/eton/kandr2/"]http://users.powernet.co.uk/eton/kandr2/[/url] | |
Re: >I am wondering what the "using namespace std;" statement is all about. It's a modern, standard C++ (as opposed to old, pre-standard C++) way to use an unadorned [font=Courier New]cout[/font] (for example), which is a member of the [font=Courier New]std namespace[/font]. [url="http://www.cpp-home.com/forum/viewtopic.php?t=252"]Here[/url] are a few more details. | |
Re: >Can anyone shed any light on this. [quote][font=Times New Roman]The [/font][b][font=Courier-Bold]pow [/b][/font][font=Times New Roman]functions compute [/font][b][font=Courier-Bold]x [/b][/font][font=Times New Roman]raised to the power [/font][b][font=Courier-Bold]y[/b][/font][font=Times New Roman]. A domain error occurs if [/font][b][font=Courier-Bold]x [/b][/font][font=Times New Roman]is finite and negative and [/font][b][font=Courier-Bold]y [/b][/font][font=Times New Roman]is finite and not an integer value. A domain … | |
Re: You might try something like this.[code]#include <stdio.h> #include <math.h> [color=red]int[/color] main() { double p,min,max,temp; double pymt[3][100],total[3][100]; int a=0; int n; printf ("Enter loan amt(p): "); scanf ("%lf",&p); printf ("\nKey in minimun interest rate(i): "); scanf ("%lf",&min); printf ("\nKey in maximun interest rate(i): "); scanf ("%lf",&max); printf("%s\t%s\t%s\t%s\n","Monthly payment","Total payment","Interest rate in … | |
Re: (4) [url="http://www.eskimo.com/~scs/C-faq/q12.20.html"]Avoid scanf[/url].:p | |
Re: [QUOTE=.·)Tusky(·.][b]Well, I put in a number and then it worked not as i planed although.[/b][/QUOTE]In the code you posted, [font=Courier New][color=red]Value[/color][/font] does not have a value (as the error message tried to tell you). [QUOTE=.·)Tusky(·.][b]First i enterd the first, then the second, then the third. Then it just shuts the … | |
Re: [url="http://www.cppworld.com/forum/index.php?showtopic=474&st=0&#entry3390"]Here is some code[/url] that might get you started or give you ideas. You may want to work with it a bit and then post your latest attempt with any remaining questions. | |
Re: [QUOTE=meabed][code] #include <iostream> using namespace std; [color=red]int[/color] double Square (double Value); [color=red]int[/color] main () { double Number, SquaredNumber; Number = 5; SquaredNumber = Square (Number); cout << SquaredNumber << endl; return 0; } [color=red]int[/color] double Square (double Value) { double SquareReturn; SquareReturn = Value * Value; return SquareReturn; } [/code][/QUOTE]What … | |
Re: [QUOTE=coolice]BTW : Can I count on the fact that in any windows environment, the absolute maxium for a file or directory name length can not exceed 256 ? [/QUOTE]I might choose to use the standard macro [font=Courier New]FILENAME_MAX[/font]. | |
Re: I'd be careful with the [font=Courier New]<=[/font], and I wish I'd spent more time looking into the 'Why doesn't this work?', but you may want to try something like this. [code]#include <stdio.h> size_t FillAgeList(int ageList[], size_t size) { size_t i, counter = 0; /* Reads the data from .dat file … | |
Re: [QUOTE=psk]can anyone tell me whether ifs function is a member function of ifstream.[code]ifstream ifs( g_pSystemEnvironment->GetTotAlmCountFileName() );[/code]i am not able to understand the code. could anyone help me out of it.[/QUOTE]Here [font=Courier New]ifs[/font] is not a function. It is an object of type [font=Courier New]ifstream[/font]. It is being instantiated using a … | |
Re: [QUOTE=sroberts82]sorry, I mean in C.[/QUOTE]Check out the [font=Courier New]strtol[/font] example [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043372399&id=1043284385#opt3"]here[/url]. It can be easily adapted to floating point instead of integer input by instead using [font=Courier New]strtod[/font]. | |
Re: Obfuscated for the sake of being too homework-sounding with no work presented.[code]#include <stdio.h> [color=blue]char *f(char*s){char*t=s,*u=t;while(*u)++u;--u;[/color] [color=blue]while(t<u){char x=*t;*t++=*u;*u--=x;}return s;}[/color] int main ( void ) { char text[] = "The quick brown fox"; puts ( text ); puts ( f ( text ) ); return 0; } /* my output The quick … | |
Re: Our friend [font=Courier New][url="http://www.eskimo.com/~scs/C-faq/q12.20.html"]scanf[/url][/font] claims another victim.[code]#include <stdio.h> int main(void) { int x, min, max; printf("Enter val for max and x\n"); scanf("%d%d",&max,&x); min = x > max ? max : x; printf("%d\n",min); return 0; }[/code] | |
Re: Max() and Min() don't account for negative numbers. You may want to initialize the Maximum and Minimum to the first element of the list. The summing routine can be done mathematically without a loop. | |
Re: Did you mean to [i]call[/i] the function?[code]case 4:{ clrscr(); affichage2(); /* <===== BUG : Declaration is not allowed here */ }[/code] | |
Re: [QUOTE=Richard Wong]Goal: I would like to assign the content of a known function to a function pointer in LINUX environment. Problem: Get segmentation fault when running the function pointer after assignment. Procedure: 1). declare a funtion pointer. [color=red]2). Allocate memory space to the function pointer using the function' malloc'[/color] [color=red]3). … | |
Re: >What is a vending machine exactly?! Something like [url=http://www.e-vending.com/snack_pop_vending_machines.htm]this[/url]. | |
Re: When you return from your proposed function, the local data goes out of scope. So it is not useful to do it this way. Could you describe what it is you would like to accomplish? | |
Re: Ah, yes, [font=Courier New][url="http://www.eskimo.com/~scs/C-faq/q12.20.html"]scanf[/url][/font]. Trouble is almost guaranteed until you decide to quit using it. | |
Re: [code]#include <iostream> #include <cstdlib> #include <cctype> int main() { const char text[] = "371", *digit; int value, sum, cube; // Use the text from most significant digit to least significant digit for ( digit = text, sum = 0; *digit; ++digit ) { value = *digit - '0'; cube = … | |
Re: [QUOTE=MaxC]Hello guys, is there a way to declare global variables as [b]float[/b] and then convert them to [b]int[/b] to be used in a function? i.e. [CODE] float num1, num2, result; float Mod(){ num1%num2=result; //Wrong, (%) requires [b]int[/b] type) }[/CODE][/QUOTE]The [font=Courier New][url="http://www.rt.com/man/fmod.3.html"]fmod[/url][/font] function returns the remainder of floating point division. | |
Re: [code]members = strlen(bob.c_str());[/code]Perhaps? | |
Re: If you have conio.h...[code]#include <stdio.h> #include <conio.h> #include <ctype.h> #define ESC 27 #define UP 72 #define LEFT 75 #define RIGHT 77 #define DOWN 80 void foo(const char *prompt) { puts(prompt); for ( ;; ) { int ch = getch(); switch(ch) { case EOF: case ESC: return; case UP: puts("UP"); break; … | |
Re: Something like this?[code]#include <stdio.h> #include <time.h> int main(void) { time_t now, then = time(&now) + 5; if ( now != (time_t)(-1) ) { const char *text[] = {"Hello","World"}; size_t i = 0; for ( ;; ) { printf("\r%s", text[i]); fflush(stdout); if ( ++i >= sizeof text / sizeof *text ) … | |
Re: Try adding a space between int and _stdcall. In the future, try to put your code between [code][/code]. For example, writing the following... [code] #include<windows.h> int _stdcall WinMain(HINSTANCE i, HINSTANCE j, LPSTR k, int l) { MessageBox(0,"Hi","Title",0); return(0); } [/code] ...will produce the following: #include<windows.h> int _stdcall WinMain(HINSTANCE i, HINSTANCE … | |
Re: [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp]Serial Communications in Win32[/url]? | |
Re: Your only constructor takes two parameters.[code]// Constructor RationalNumbers::RationalNumbers( double num, double den ) { num=numerator; if (den>0) {den=denominator;} }[/code]But you instantiate some objects without supplying parameters.[code] RationalNumbers x; RationalNumbers a; RationalNumbers b;[/code]1. You need to define a constructor that takes no parameters.[code]// Constructor RationalNumbers::RationalNumbers( ) : numerator(0.0), denominator(1.0) {}[/code]2. Or … | |
Re: >I am working on trying to get it to work for 3 dimensions + but I would like to see how others implement this. Just keep following the pattern. #include <iostream> void foo(std::size_t x, std::size_t y, std::size_t z) {int q = 0, ***array; // Create and initialize dynamic 3-D "array" … | |
Re: [code]int get_input (int *firstTerm, int *secondTerm, int *thirdTerm, int *fourthTerm, int *fifthTerm, int *sixthTerm); /* ... */ int main (void) { /* ... */ get_input (&fourthTerm, &fifthTerm, &sixthTerm);[/code]If you were the compiler and the programmer told you to expect six arguments and the programmer only gave 3, would you be … | |
Re: >How am i supposed to write a code in c which compiles in c but not in c++[code]#include <stdio.h> int main(void) { char new[] = "Compiles in C, not in C++"; puts(new); return 0; }[/code]That is, one way would be to use a C++ (and not C) keyword as a … |
The End.