218 Posted Topics
[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 …
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, …
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.
[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]
[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>).
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 …
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.
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.
Do you have to print to the printer directly? And is this related to your other thread?
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 …
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].
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 { …
[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]
[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 …
You probably want to use [url=http://www.cplusplus.com/ref/cstring/strchr.html]strchr()[/url] for that.
[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.
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]
Try this: [code]Node array[DEPTH][ROW][COL] = {{{NULL}}};[/code] That should get rid of your error and your warning.
[inlinecode]return 0;[/inlinecode]? :)
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]
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).
[code]string s; a_function_that_takes_a_cstring(s.c_str());[/code]
In C you can use stricmp() (or _stricmp() with the Microsoft compilers). Or you can write your own function, as Ancient Dragon suggested.
[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]
[quote]call rand % numberOfStringInTheArray to get a ranom int to represent the row of the table to use.[/quote] See Narue's site. :)
[quote]Notice the complete lack of parameters which means that it takes no parameters.[/quote] In C++, yes. In C, no. :)
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]
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.
Post your source instead of just the header file. The header file won't help too much.
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]
[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]
[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. :)
Post your code. We can't do much if there's no code.
[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 …
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]
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.
[code]double rounded = (double)((int)((unrounded*1000)+.5)/1000);[/code]
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]
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]
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 …
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 …
[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.
Have you tried yet? You might want to use a struct/class for C/C++.
[quote]12. Is this job risky? [/quote] Not usually.
You're using [b]stack[/b] in RPN() as if it was a global variable, when in fact it is local to main().
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 …
[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.
[code] int main() { // ... return 0; getch(); }[/code] Oops. :)
[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) : …
The End.