218 Posted Topics

Member Avatar for nabil1983

[list=1] [*][inlinecode]fflush(stdin);[/inlinecode] Do [i]not[/i] use that. (Nor gets.) Use this: [code]int c; while((c = getchar()) != '\n' && c != EOF);[/code] [*]getch() is nonstandard and you shouldn't use it; but if you must, it's in <conio.h>. [*][inlinecode]scanf("%s",cdDB[i].Artist);[/inlinecode] This is a bad way to read in a string (although, admittedly, better …

Member Avatar for dwks
0
228
Member Avatar for That Man

You might want to use doubles instead of floats for greater accuracy. [quote]Multi-Function Calculator - Ask the user for 2 numbers, then ask them to select from a numbered list of operations.[/quote] You can do this with cin; use first two doubles and then a char. [quote]As rudimentry error checking, …

Member Avatar for shaikh_mshariq
0
406
Member Avatar for jhdobbins

With fgets(), you risk not flushing the entire buffer, and with a single getchar() you have the same problem. The best solution is this: [code]int c; while((c = getchar()) != '\n' && c != EOF);[/code] c has to be an int because EOF is an int value.

Member Avatar for Ancient Dragon
0
251
Member Avatar for pit_bull

[quote]getchar();[/quote] Ther are better ways to clear the input buffer: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044873249&id=1043284392[/url]

Member Avatar for agiorgio
0
110
Member Avatar for Jon182

[code]char * ch = array; while((ch = strstr( ch, "hello")) != 0) { if(ch != array && !isspace(ch[-1])) continue; Count++; ch++; } [/code] That should work. And yes, array[-1] is valid. :) isspace() is in <ctype.h> (or, in C++, <cctype>).

Member Avatar for agiorgio
0
189
Member Avatar for brianotieno

Put your code in [code][/code] tags. class box:Protected rectangle -> class box : protected rectangle All C++ keywords are in lowercase. void main() It's int main(). #include"mybox.cpp" You shouldn't include .cpp files. Use a project instead. void box::seta,b,c,(int a,int b,int c,); { lenght=a; widht=b; height=c; } You have an extra …

Member Avatar for dwks
0
139
Member Avatar for DotNetUser

In C you would use realloc(). In C++ you have to emulate it. Allocate the new area, copy the old stuff to the new area, and free the old area.

Member Avatar for dwks
0
60
Member Avatar for egor

Is this program to be in C or C++? Hint: You'll need two for loops (one inside the other) to read the values into the array.

Member Avatar for dwks
0
106
Member Avatar for muthuivs
Member Avatar for muthuivs
0
2K
Member Avatar for muthuivs
Member Avatar for xjim72

You have to decrement listSize if you don't want it to print -999. eg [code] cout <<"Enter a maximum of 100 positive integers ending with -999"<<endl; readNum (Numbers, listsize); [b]listSize--;[/b] cout <<endl; cout <<fixed<<showpoint<<setw(7)<<"Number"<<setw(9)<<"Count"<<endl;[/code] [quote]I get repeat info[/quote] Show the output. [quote]suggestion: read the 100 numbers from a file instead …

Member Avatar for xjim72
0
888
Member Avatar for dreamreaver

You can't hope to compile a C++ program with Turbo C. In fact, you can't hope to compile some C programs with Turbo C. Get a better compiler. Top of the list: Dev-C++ ([url]http://www.bloodshed.net)[/url].

Member Avatar for SpS
0
160
Member Avatar for midwesternstyle

Use [CODE] tags. float sum (void) { if(sum<=1) { sum = sum + numerics; lcd_print_float (sum); else(sum=numerics-1) { lcd_print_float(sum) } } } Probably not what you wanted, eh? Maybe you meant something like this: float sum (void) { if(sum<=1) { sum = sum + numerics; lcd_print_float (sum); } else { …

Member Avatar for midwesternstyle
0
147
Member Avatar for kharri5

[quote]I need something that will test: command | command | command too. I just don't know enough commands...heh) [/quote] Try this: [code]$ ls ~/*.c | perl -ne 'y|.*/||;print' | less[/code] Or a Windows one: [code]C>dir /on/b *.c | more[/code]

Member Avatar for kharri5
0
133
Member Avatar for ultimate_fusion

[quote]i have downloaded the sdk directx9 and installed and put the lib and include files in the dev-c++ directory.[/quote] The files don't go in the same directory. Include files go in $DEVCPPDIR/include and library files in $DEVCPPDIR/lib (I think). [quote]e.g redefinition of struct D3DVECTOR[/quote] You must have some other version …

Member Avatar for dwks
0
111
Member Avatar for Acidburn

You probably want to use [url=http://www.cplusplus.com/ref/cstring/strchr.html]strchr()[/url] for that.

Member Avatar for dwks
0
91
Member Avatar for sosy2001

[code]// variable of new type StudentRecord [color=red]//[/color][/code] -> [code]// variable of new type StudentRecord[/code] You don't need //'s at the end of your single-line comments. Single-line comments terminate at a newline.

Member Avatar for dwks
0
131
Member Avatar for fevershark

You can delete it the same way, too. [code]class MyClass { // blabla }; int n = 5; // allocate an array of class objects MyClass* pClassA = new MyClass[n]; // // allocate only one class object MyClass* pClass = new MyClass; // ... delete [] pClassA; delete pClass; [/code]

Member Avatar for dwks
0
146
Member Avatar for tyczj

Try this: [code]Node array[DEPTH][ROW][COL] = {{{NULL}}};[/code] That should get rid of your error and your warning.

Member Avatar for dwks
0
153
Member Avatar for Acidburn
Member Avatar for Subterraneus

No, you just have to pass system() a character array. C code: [code] int x = 9; char s[100]; sprintf(s, "echo %i", x); system(s);[/code]

Member Avatar for Subterraneus
0
154
Member Avatar for Nickol

Use [CODE] tags. You can use C++-style strings and the find() function. Or you can use strstr(). Or you can stick with for loops. Hint: ignore chars until you reach a space (or until isspace() (in <ctype.h>/<cctype>) returns non-zero).

Member Avatar for Nickol
0
121
Member Avatar for DotNetUser
Member Avatar for DotNetUser
0
112
Member Avatar for DotNetUser

In C you can use stricmp() (or _stricmp() with the Microsoft compilers). Or you can write your own function, as Ancient Dragon suggested.

Member Avatar for DotNetUser
0
201
Member Avatar for Aldin

[qoute] -> [quote] time() etc are in <time.h> (for C) or <ctime> (for C++). struct tm contents: [url]http://members.aol.com/wantondeb/#tmstruct[/url]

Member Avatar for masa
0
463
Member Avatar for kahaj

[quote]call rand % numberOfStringInTheArray to get a ranom int to represent the row of the table to use.[/quote] See Narue's site. :)

Member Avatar for winbatch
0
185
Member Avatar for some one

[quote]Notice the complete lack of parameters which means that it takes no parameters.[/quote] In C++, yes. In C, no. :)

Member Avatar for iamlearning
0
123
Member Avatar for sam1

You'll want <cstring> for strcmp(). I think [BookD].authorsurname is either Objective C or an attempt to do this: [code](*BookD).authorsurname[/code] [edit] Or maybe it's Java, judging by his avatar. :) [/edit]

Member Avatar for dwks
0
212
Member Avatar for Karl1

What compiler are you using? What OS? You might try sound() which outputs a given frequency through the PC speaker. Just don't forget to call sound(0) when you're done or you'll have sound coming out of the speaker until you turn the computer off.

Member Avatar for dwks
0
47
Member Avatar for sunlight

Post your source instead of just the header file. The header file won't help too much.

Member Avatar for dwks
0
123
Member Avatar for TimC

Sorry, I can't view your file (this stupid computer doesn't have WinZIP!), but I'm going to guess you're not clearing the keyboard buffer. This will clear the keyboard buffer (it's in C): [code]int c; while((c = getchar()) != '\n' && c != EOF);[/code]

Member Avatar for winbatch
0
289
Member Avatar for magikman

[code]#define AND &&[/code] [b]and[/b] is already a keyword to that effect (in C++; and C too if you include a header file). [code]void inputfn(B_Days friends[51], int &count) { count=0;[/code] -> [code]void inputfn(B_Days friends[51], int &count) { [color=blue]int[/color] count=0;[/code]

Member Avatar for magikman
0
179
Member Avatar for desertstorm

[code]int Read(char *buffer, int size, OpenFileId id); void Write(char *buffer, int size, OpenFileId id);[/code] buffer is the string containing data you want to read or write. size is the length of that buffer (probably strlen(buffer)+1). id is the file id. I'm just guessing here. :)

Member Avatar for jim mcnamara
0
131
Member Avatar for complete
Member Avatar for frankieb

[quote]What are the (2) categories of ANDs and ORs and how can they be described?[/quote] You mean truth tables? [code] AND in1 in2 out 0 0 0 0 1 0 1 0 0 1 1 1 OR in1 in2 out 0 0 0 0 1 1 1 0 1 1 …

Member Avatar for frankieb
0
111
Member Avatar for Naveena

And probably C ones, too, if you don't [inlinecode]#include <stdlib.h>[/inlinecode]. I like this one: [code]int main(void) { int is_c = 2//**/2 -2; }[/code] although it compiles in C and C++. Try this: [code]struct class {};[/code]

Member Avatar for SpS
0
123
Member Avatar for free_eagle

Don't use void main(). [quote]and What does short circuit evaluation means in c?[/quote] [code]if(a() && b())[/code] In this case, if a is false, b won't be evaluated, because no matter what b is, the expression is false.

Member Avatar for free_eagle
0
165
Member Avatar for Valmian
Member Avatar for dwks
0
348
Member Avatar for nabil1983

Don't use gets(). It's dangerous. Use fgets() instead. ([url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1049157810&id=1043284351[/url]) fflush(stdin) is also wrong. ([url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351[/url]) main() should return a value. [inlinecode]printf("%d",[color=red]&[/color]ch);[/inlinecode]

Member Avatar for dwks
0
182
Member Avatar for Naveena

C99: [code]int main(void) { _Bool b; return 0; }[/code] C89: [code]int main(void) { double x = 1 //**/ 10; return 0; } [/code] For the second program, C++/C99 sees the double line as [code]double x = 1 [i][color=blue]//**/ 10;[/color][/i][/code] whereas C89 sees it as [code]double x = 1 /[i][color=blue]/**/[/color][/i] 10;[/code]

Member Avatar for dwks
0
146
Member Avatar for ehab_aziz2001

And next time use CODE tags. :) You need prototypes. Valid ones. Put this near the top of your program: int pay_calc(int emp_w, int emp_r, char emp_u); Or double or float or whatever it is you want. If there is no prototype for a function, the compiler assumes it takes …

Member Avatar for dwks
0
112
Member Avatar for akki_freak

In C: [code]int **a, x; a = malloc(sizeof(int *) * 10); for(x = 0; x < 10; x ++) { a[x] = malloc(sizeof(int) * 3); } /* ... */ for(x = 0; x < 10; x ++) { free(a[x]); } free(a); [/code] You can even enlarge the array, or shrink …

Member Avatar for dwks
0
237
Member Avatar for TimC

[code]doctor* Array[5]; for(int i=0;i<2;i++) [/code] Array isn't initialized. And if it was, you're only looping through two of its five elements.

Member Avatar for WolfPack
0
164
Member Avatar for coolgal
Member Avatar for coolgal
0
224
Member Avatar for sheldonhigh16
Member Avatar for dwks
0
77
Member Avatar for btech

You're using [b]stack[/b] in RPN() as if it was a global variable, when in fact it is local to main().

Member Avatar for iamthwee
0
243
Member Avatar for loganb

It's [[b]/[/b]code], not [[b]\[/b]code]. :) You're declaring variables in the middle of a block, which is C++/C99. [code] if((des=fopen(FILENAME,"r"))==NULL) printf("The file was not opened, HAHA\n");[/code] Might want to exit at this point. [quote]When I execute the code it gives me the error opening files message.[/quote] Which message? Perhaps the file …

Member Avatar for winbatch
0
74
Member Avatar for nabil1983

[list=1] [*]Don't use [b]void[/b] main(). Use [b]int[/b] main() and [inlinecode]return 0;[/inlinecode]. [*]You shouldn't use [inlinecode]scanf("%s", string);[/inlinecode]. As Salem says, it's a poor replacement for gets(). Use fgets() instead. [/list] You don't print anything.

Member Avatar for perniciosus
0
114
Member Avatar for iqbal
Member Avatar for dwks
0
171
Member Avatar for Acidburn

[code]Date::Date() { day = 15; month = 03; year = 4; } Date::Date(int d, int m, int y) { day = d; month = m; year = y; }[/code] -> [code]Date(int d = 15, int m = 3, int y = 5) //... Date::Date(int d, int m, int y) : …

Member Avatar for dwks
0
78

The End.