Forum: C++ 5 Days Ago |
| Replies: 12 Views: 384 Are you opening the output file in binary mode?
[edit]Another curiosity that I did no investigation of...
ofstream myfile("foo.txt", std::ios::binary);
for ( int x = 0; x <... |
Forum: C++ 5 Days Ago |
| Replies: 12 Views: 384 Peeking at the index, I get a little confused with the x and y and your index calculation. But, does reversing the loop order give you more of an expected result? That is, from
for ( int... |
Forum: C++ 5 Days Ago |
| Replies: 12 Views: 384 Simply reading in and writing out, I get equivalent files:
#include <iostream>
#include <cstdio>
int main()
{
FILE *out, *in = fopen("in.dat", "rb");
if ( in )
{
int... |
Forum: C++ 5 Days Ago |
| Replies: 12 Views: 384 PPM is part of the PNM (Portable Anymap Format) file type. i.e. Coloured Image, but it's competely uncompressed, so it pretty much is plain text file in that sense.
In terms of "little integers"... |
Forum: C++ 5 Days Ago |
| Replies: 12 Views: 384 If it's a text file, and apparently PPM is or is it? (http://en.wikipedia.org/wiki/Portable_pixmap), don't mess with binary mode. Also, don't write "little integers" that happen to be characters as... |
Forum: C++ 8 Days Ago |
| Replies: 9 Views: 422 http://parashift.com/c++-faq-lite/mixing-c-and-cpp.html |
Forum: C++ 10 Days Ago |
| Replies: 2 Views: 119 Using gcc?
gcc -E main.cpp
[edit]Some code...
#include <stdio.h>
#define SetMacro(name,type) \
virtual void Set##name (type _arg)
SetMacro(foo,int)
{ |
Forum: C++ 11 Days Ago |
| Replies: 8 Views: 208 Or change the scope of i. Remember to return a value. And to initialize sum.
float getAverageGrade (float grades[], int count)
{
float sum = 0;
float average;
int i;
for (i=0; i<count;... |
Forum: C++ 12 Days Ago |
| Replies: 8 Views: 249 Oh, my. Don't expect to learn C or C++ in the course you are taking.
User Input: Strings and Numbers [C++] (http://www.daniweb.com/tutorials/tutorial71858.html)
User Input: Strings and Numbers... |
Forum: C++ 12 Days Ago |
| Replies: 22 Views: 460 No.
Spot the difference:
cout << (first_name, last_name);
cout << concat(first_name, last_name);
Same thing. Pick your favorite. |
Forum: C++ 12 Days Ago |
| Replies: 22 Views: 460 Call the function...?
And don't forget to null terminate the full_name in |
Forum: C++ 13 Days Ago |
| Replies: 2 Views: 176 I only skimmed your question, but it sounded like:
http://parashift.com/c++-faq-lite/templates.html#faq-35.12
[edit]Short fix?
//Main.cpp
#include <stdio.h>
#include <string.h>
#include... |
Forum: C++ 13 Days Ago |
| Replies: 22 Views: 460 You can see that that might be close but not right. Why the difference in handling of title vs first_name and last_name in the loops? Wouldn't you suppose they'd all be similar?
nclude <iostream>... |
Forum: C++ 13 Days Ago |
| Replies: 6 Views: 306 Yeah. Some the copying should be done a bit different from what you have. Some ideas:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int count, i, j = 0, k = 0;
... |
Forum: C++ 13 Days Ago |
| Replies: 6 Views: 306 I don't see where you're trying to display it. Can you post the code? |
Forum: C++ 13 Days Ago |
| Replies: 6 Views: 306 Say, why not show us the code? |
Forum: C++ 20 Days Ago |
| Replies: 2 Views: 246 http://c-faq.com/aryptr/dynmuldimary.html |
Forum: C++ 20 Days Ago |
| Replies: 8 Views: 369 How about something along this line?
nclude <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream iptilvar("ip.txt"); //open filestram
string line, ip; |
Forum: C++ 22 Days Ago |
| Replies: 2 Views: 414 Are necessary headers #included prior to the lines in question?
The functions calls shouldn't have the [] part.
Do your headings have the curly-brace part?
Your code may be long, but you've... |
Forum: C++ 22 Days Ago |
| Replies: 8 Views: 533 My assistance has been subpar tonight. Try this:
void loadFileToArray (string namesArray[], double gradesArray[][4], int &numberOfStudents)
{
string filename;
ifstream inputDataStream;
... |
Forum: C++ 22 Days Ago |
| Replies: 8 Views: 533 Ah! Separate lines for the names and the grades! I stand corrected. My crystal ball file looked like this:
5
foo 95 84 72 87
bar 91 77 82 63
baz 75 63 66 42
qux 50 49 33 58
moo 92 95 97 91
noo... |
Forum: C++ 22 Days Ago |
| Replies: 8 Views: 533 I don't have this file or some other one that apparently works for you. From what I was tinkering with, I would be surprised with it having ever worked correctly. And since I haven't seen the input... |
Forum: C++ 22 Days Ago |
| Replies: 8 Views: 533 You've got nested loop issues.
After you get the line, the line is got. Reading "the rest of the line" will be problematic.
You should check for success when you attempt to read from the file.... |
Forum: C++ 25 Days Ago |
| Replies: 3 Views: 237 Keep track of the index of the highest value while taking input. Initialize to the first element:
int hi = 0;
When you find a new highest value, capture the index:
if ( votes[i] >... |
Forum: C++ 32 Days Ago |
| Replies: 5 Views: 255 You seem to be using a lousy code editor and have "fancy quotes" instead of the plain variety. After that you'll get more syntax errors to clean up, like this
int calc_bonus(int sales){
You need to... |
Forum: C++ Nov 15th, 2009 |
| Replies: 11 Views: 549 That happens to be true for the garden variety PC of today, but it is not true as a generic statement. |
Forum: C++ Nov 9th, 2009 |
| Replies: 3 Views: 308 #include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "RAND_MAX = " << RAND_MAX << "\n";
return 0;
} |
Forum: C++ Nov 8th, 2009 |
| Replies: 2 Views: 196 Lose the semicolon:
#define CAPACITY 128;
[edit]Avoid expressions like this:
i=(i++)%CAPACITY
http://c-faq.com/expr/ieqiplusplus.html |
Forum: C++ Nov 8th, 2009 |
| Replies: 4 Views: 290 Another way of reading "7 times per line" is "output a newline every 7 times". You could do this with a separate counter (in the same loop though!) that counts to 7, outputs a newline and then is... |
Forum: C++ Nov 3rd, 2009 |
| Replies: 6 Views: 634 Well, choose your poison: multiple passes of the same file, or a single read with a buffer. Both are relatively simple, I'd recommend just examining what's there. Experiment a bit. Learning to code... |
Forum: C++ Nov 3rd, 2009 |
| Replies: 6 Views: 634 I suppose you could read the file to count the lines and then back up and only print the last 10.
Why the extra condition now?
Why don't you give the coding a shot first? |
Forum: C++ Nov 3rd, 2009 |
| Replies: 6 Views: 634 I'd just read all lines of the file into a circular buffer with 10 strings, each containing a line. When you get to the end of the file, you will have the last 10 lines stored.
#include <iostream>... |
Forum: C++ Nov 1st, 2009 |
| Replies: 12 Views: 416 You're going to return from main in one of two places:
int main ()
{
int number;
int counter = 0;
int flags = 1;
bool flag_none = true;
bool fag_yes = false;
cout << "Enter a number,... |
Forum: C++ Nov 1st, 2009 |
| Replies: 12 Views: 416 The following code is unreachable:
if (counter < 7 == true)
{
cout << "Number " << counter << " is between 10 and 500" << endl;
cout << "Number " << counter << " is not flagged. " << endl;
}... |
Forum: C++ Nov 1st, 2009 |
| Replies: 12 Views: 416 |
Forum: C++ Oct 29th, 2009 |
| Replies: 7 Views: 349 I had to patch some syntax errors to get to the link, so I'm not sure why you weren't seeing them. With regard to the linker errors:
http://parashift.com/c++-faq-lite/templates.html#faq-35.12 ? |
Forum: C++ Oct 25th, 2009 |
| Replies: 14 Views: 383 No I don't. But it is working now thank you![/QUOTE]This would be an equivalent:
for ( int x=0; x<3; x++ )
{
/* empty loop */
} |
Forum: C++ Oct 25th, 2009 |
| Replies: 14 Views: 383 for ( int x=0; x<3; x++ );
Do you know what the semicolon does to your intended loop? |
Forum: C++ Oct 22nd, 2009 |
| Replies: 6 Views: 385 Hm. I don't see the mention -- perhaps it's my eyesight. But no matter. Clarification achieved.
I don't think I'd call it a compiler issue. I would think that perhaps there oughtta be a way to... |
Forum: C++ Oct 22nd, 2009 |
| Replies: 6 Views: 385 You kinda need to know whether the binary contains LE or BE data.
Some somewhat related FAQs:
http://c-faq.com/misc/endiantest.html
http://c-faq.com/cpp/ifendian.html... |