Search Results

Showing results 1 to 40 of 286
Search took 0.08 seconds.
Search: Posts Made By: Dave Sinkula ; Forum: C++ and child forums
Forum: C++ 5 Days Ago
Replies: 12
Views: 384
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
http://parashift.com/c++-faq-lite/mixing-c-and-cpp.html
Forum: C++ 10 Days Ago
Replies: 2
Views: 119
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
Call the function...?

And don't forget to null terminate the full_name in
Forum: C++ 13 Days Ago
Replies: 2
Views: 176
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
Say, why not show us the code?
Forum: C++ 20 Days Ago
Replies: 2
Views: 246
Posted By Dave Sinkula
http://c-faq.com/aryptr/dynmuldimary.html
Forum: C++ 20 Days Ago
Replies: 8
Views: 369
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
#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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
[edit]Er, wait...
Forum: C++ Oct 29th, 2009
Replies: 7
Views: 349
Posted By Dave Sinkula
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
Solved: String issue
Views: 383
Posted By Dave Sinkula
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
Solved: String issue
Views: 383
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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
Posted By Dave Sinkula
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...
Showing results 1 to 40 of 286

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC