Tom Gunn 1,164 Practically a Master Poster

Why not change the locale to something that uses ',' as the radix character? Then you don't have to do any mumbo jumbo with strings:

#include <iostream>
#include <locale>
#include <sstream>

using namespace std;

int main()
{
    istringstream is("12,34");
    double a = 0;

    is.imbue(locale("german_germany.1252"));

    is >> a; // will recognize ',' as a radix
    cout << a << '\n';
}
jephthah commented: sweet. i lernt something today. +13
Nick Evan commented: as did I. +22
Tom Gunn 1,164 Practically a Master Poster

>>char EVENT_NAME;

That only declares a single character. you need an array, such as char EVENT_NAME[255]; or better yet string EVENT_NAME;

Please remember that if you use an array with operator>>, you also need to lock the upper limit so that cin does not overflow the array:

char EVENT_NAME[255];

// setw() is declared in the <iomanip> header
// the size for setw includes a null character for the array
while (in >> setw(255) >> EVENT_NAME)
{
    cout << EVENT_NAME << "\t"  << endl;
}

The string class is better because it grows dynamically. You do not need to worry about array overflow or how to deal with extra long strings.

Ancient Dragon commented: Thanks for the correction :) +36
tux4life commented: Nice one here :) +16
Tom Gunn 1,164 Practically a Master Poster
if ( infile ){
	    
		list = read_file( &infile, &lines );   
	        infile.close();

}

I did this and I still get the same result.

When I cout << infile I get an address the first time and 0 the next time.

Ancient Dragon already said you needed to clear the errors too. If you read an ifstream to the very end, the eofbit is set and won't let you do any more reading even if you close the file and open another one. The two states are separate. After closing, clear the error state:

list = read_file( &infile, &lines );   
infile.close();
infile.clear();
Tom Gunn 1,164 Practically a Master Poster

Shouldn't the compiler be reporting that?

How is the compiler supposed to know? All it sees is a char pointer, not a char pointer to read only memory. The compiler assumes you know what you're doing and doesn't slow down compilation with expensive checks to protect you from something like that.

If you want that kind of protection, you need to help the compiler along by using const char *p instead of char *p when pointing to something that shouldn't be modified.

Tom Gunn 1,164 Practically a Master Poster

I want to not see any warnings at all when I build.

I haven't seen many warnings that were so asinine they could be completely ignored. Disabling warnings just so you can get a clean compile is not a recommended practice because fixing them almost always makes your code better.

Separating warnings and errors makes sense, and that's the only time I can think of where you might want to use -Wno. But a better way to split up the errors and warnings is redirecting the output of the compiler to a file and then grepping the file on warnings and then errors. That way you don't lose any output and still have a way of focusing on one or the other.

Tom Gunn 1,164 Practically a Master Poster

The method is marked as const, so calling find on DoubleValues will use the overload that returns a const_iterator. You can't assign a const_iterator to an iterator, but because the method is const, it should be safe enough to change the iterator like this:

bool OrientedPoint::getDoubleValue(const std::string &ValueName, double &Value) const
{
    std::map<std::string, double>::const_iterator MyIter;
    MyIter = DoubleValues.find(ValueName);

By the way, it's cleaner and usually more efficient to initialize objects in the constructor instead of through assignment:

bool OrientedPoint::getDoubleValue(const std::string &ValueName, double &Value) const
{
    std::map<std::string, double>::const_iterator MyIter = DoubleValues.find(ValueName);
Tom Gunn 1,164 Practically a Master Poster

The overload is not needed. As long as the function parameter is a const reference to string, you can pass a string constant and it will become a string object. Libraries usually have the overload to avoid the cost of constructing a new string object, but it is not required.

Tom Gunn 1,164 Practically a Master Poster

A little addition on:

Array names become pointers

Yes, an array name is a constant pointer to the first element of that array.

An array name is the name of an array object, nothing more, nothing less. When used as a value, it is converted to a pointer to the first element. When used as an object, there is no conversion. It's a subtle difference, but important when you get to object usage like char a[] = "string" , &a , and sizeof(a) . All of those work the right way because the array is not converted to a pointer.

tux4life commented: Yes you're right :) +15
Tom Gunn 1,164 Practically a Master Poster

i would like to ask if this method should be called after ever cin statement?

For anyone else reading, the method in question is here. This thread used to be a post in that thread.

operator>>() is the problem child here. It works something like this:

// beware: pseudo-code
ostream& operator>>(ostream& os, T obj)
{
    SkipWhiteSpace(os);
    ReadObject<T>(obj);
    return os;
}

Any white space after the object will not be touched until the next call to operator>>(). If the stream has " abcd\nefgh" , here is what happens:

cin >> s1;        // s1 == "abcd"
getline(cin, s2); // s2 == ""
getline(cin, s3); // s3 == "efgh"

operator>>() does its thing by skipping leading white space and reading the object. It stops on white space thinking that the next call to operator<<() will skip it. But getline does not skip leading white space, and it even uses '\n' as a stopping character by default.

You only need to use the method from that thread in cases where the next input call will give you the finger. ;) A good guideline is clear the stream after the formatted input whenever you mix formatted and unformatted input.

i was thinking of trying a loop to eat everything but i don't know if that would cause problems.

A loop is good, but it needs to stop on '\n' too, and using eof() in the loop condition should be avoided because it has the wrong behavior and there …

Tom Gunn 1,164 Practically a Master Poster

yes, you're right.

even though it works for this trivial example, not casting it properly is a bad habit to get into.

the correct way to initialize it is:

char q[16];
char *p = [b](char *)[/b]&q;
strcpy(q,"abc");

So you get the wrong type, then cast it to the right type and rely on the starting address being the same for both to make it all work out. Why not use the right type from the start and not need to cast at all?

/* better */
char q[16];
char *p = q;
strcpy(q,"abc");

Array names become pointers when used as a value. But you don't need to do any of that because q can be passed to strcpy directly, or even initialized to a string constant:

/* easier */
char q[16];
strcpy(q, "abc");
/* even easier */
char q[16] = "abc";

I can't figure out why you have a magic number of 16, but there's probably a reason. Otherwise you don't need any size if you initialize to a string constant:

/* easiest */
char q[] = "abc";

You can't get much shorter than that for a modifiable string. ;)

Salem commented: Quite so +36
tuse commented: super cool post +2
Tom Gunn 1,164 Practically a Master Poster

The read() function returns the stream, so you should be able to signal EOF to stop the first loop. On Linux it's a Ctrl+D key combination and on Windows it's Ctrl+Z.

theashman88 commented: Quick help +1
Tom Gunn 1,164 Practically a Master Poster

That's a lot of stuff to look at. Can you boil it down to something small enough to post in code tags?

Tom Gunn 1,164 Practically a Master Poster

I see your point, but why add new rules that could break a lot of existing code when RAII and libraries already cleanly solve the memory leak problem? Is there something else you're worried about besides memory leaks that makes you want to avoid pointers?

Tom Gunn 1,164 Practically a Master Poster

it seems to me if you don't use pointers then you never have memory leak type problems...

I wish that were so. :( Raw pointers are dangerous, and that's why smart pointers and RAII are so important. Even if you use the troublesome auto_ptr, your leak problem can be fixed:

std::auto_ptr<Employee> emp;

if (condition1)
    emp.reset(new Employee());
else if (condition2)
    emp.reset(new Manager());

The reason your second example does not work is because the new object goes out of scope at the end of the conditional block. If you use new then the object is not bound by scope restrictions as long as you have a pointer to it.

Tom Gunn 1,164 Practically a Master Poster

2D array arguments need a size for all but the first dimension. If you don't know the size until run time, or the function has to take different sized 2D arrays, you can use a pointer to a pointer instead. Then the calling code can either allocate memory to a pointer to a pointer or convert the array somehow. Note that a 2D array type is not directly convertible to a pointer to a pointer, so you have to do some kind of conversion. Here is a way that does not use malloc:

#include <stdio.h>

void f(int **p, int m, int n)
{
    int x, y;

    for (x = 0; x < m; ++x)
    {
        for (y = 0; y < n; ++y)
        {
            printf("%-4d", p[x][y]);
        }

        puts("");
    }
}

int main()
{
    int array[3][3] = 
    {
        {1, 2, 3},
        {4, 5, 6},
        {7, 8, 9}
    };
    int *p[3];
    int x;

    for (x = 0; x < 3; ++x) p[x] = array[x];

    f(p, 3, 3);

    return 0;
}

Another way is passing just a 1D pointer and calculating the size of each dimension manually. It's not portable, and I don't recommend the trick, but I haven't seen any systems yet that it doesn't work on:

#include <stdio.h>

void f(int *p, int m, int n)
{
    int x, y;

    for (x = 0; x < m; ++x)
    {
        for (y = 0; y < n; ++y)
        {
            printf("%-4d", p[x * m + y]);
        }

        puts("");
    }
}

int main() …
Tom Gunn 1,164 Practically a Master Poster

Try this code:

#include <iostream>
#include <string>

using namespace std;

void Menu();

double money = 50.00;

void Mcdonalds()
{
    cout << "Welcome\n";
    cout << "How can i help you?\n\n";
    int mcdonalds;
    cout << "1.Eat \t £2.50\n";
    cout << "2.Drink \t £1.00\n";
    cout << "3.Buy 1/6 of Mcdonalds \t £20.000\n";
    cout << "4.Leave\n";
    cin >> mcdonalds;

    switch (mcdonalds)
    {
    case 1:
        if (money >= 2.50)
        {
            cout << "You have eaten and are no longer hungery\t";
            money = money - 2.50;
            cout << "your money is: £" , money, "\n";
            Mcdonalds();
        }
        else {
            cout << "You can not afford this";
            Mcdonalds();
        }
        break;
    case 2:
        if (money >= 1.00)
        {
            cout << "You are no longer thirsty";
            money = money - 1.00;
            cout << "your money is: £" , money, "\n";
            Mcdonalds();
        }
        else {
            cout << "you can not afford this";
            Mcdonalds();
        }
        break;
    case 3:
        Mcdonalds();
        break;
    case 4:
        Menu();
        break;
    }
}

void Menu()
{
    int menu;
    cout << "You are outside\n";
    cout << "What do you want to do?\n";
    cout << "\n\n";
    cout << "1. Mcdonalds\n";
    cout << "2. School\n";
    cout << "3. Work\n";
    cout << "4. Gym\n";
    cout << "5. JD\n";
    cin >> menu;

    switch (menu)
    {
    case 1:
        Mcdonalds();
        break;
    }    
}

// home
void Home()
{
    cout << "You are at home\n";
    cout << "What do you want to do?\n";
    cout << "type either 1 or 2. numbers above 2 will also count as 2.\n";
    int home;
    cout << "1. sleep\n";
    cout …
Tom Gunn 1,164 Practically a Master Poster

then what??? looool what's the criteria??

Don't ask me, I just joined Daniweb. :(

Tom Gunn 1,164 Practically a Master Poster

You can declare a function without defining it if you replace the curly brackets and code with a semicolon:

void Menu();

void McDonalds()
{
    // ...
}

void Menu()
{
    // ...
}
rtwister commented: thanks +1
Tom Gunn 1,164 Practically a Master Poster

Just explain what is special about "essential" then?

Everyone is special. :D It's not like I pick the featured people, but if there are tons who are active, smart, and well liked, it makes sense to look for the ones that stand out somehow.

Maybe the 'every second reply is supported by helpful coding' part of the nomination made essential stand out from the list of clones.

Tom Gunn 1,164 Practically a Master Poster

if i compare number of his posts or reputation points or solved threads, i think Ramy or Scott(sknake) must be granted these before than him.

If the criteria for being featured are post count, solved thread count, and reputation points then there are a lot of people in line before essential, or the two you mentioned. There has to be some other criteria, because look at people like Salem who aren't featured but blow everyone else away.

I dont know but this is not fair, and this will demotivate our valuable posters

I think the valuable posters are more interested in being valuable than being recognized as valuable.

ddanbe commented: Nice:I think the valuable posters are more interested in being valuable than being recognized as valuable. +7
Tom Gunn 1,164 Practically a Master Poster

Without more code to look at, I can only guess. But my guess is that he didn't include the right header for strdup and casted the result to silence his compiler's warnings about it.

Tom Gunn 1,164 Practically a Master Poster

I assumed that _C was unique, but that was wrong. Regular expressions are perfect for this, but you can do it manually too:

#include <stdio.h>
#include <string.h>

int MatchCvsmPattern(const char *str, int values[4])
{
    /* find the starting value */
    while (str = strstr(str, "_C"))
    {
        const char *fmt = "_C%d_V%d_S%d_M%d%n";
        int c, v, s, m;
        int end = 0;

        /* match the pattern */
        if (sscanf(str, fmt, &c, &v, &s, &m, &end) == 4)
        {
            values[0] = c;
            values[1] = v;
            values[2] = s;
            values[3] = m;

            /* check for a pattern at the end of the string */
            if (str[end] == '\0') return 1;
        }

        str += 2; /* skip "_C" */
    }

    return 0;
}

int main()
{
    const char *samples[] = 
    {
        "ABC_DEF_GHI_JKL_C123_V45_S67_M89",
        "A11_BCDEF_CADT1_C123_V45_S67_M89",
        "TAG_NAME_C123_V45_S67_M89",
        "SEFDF_CC_C444_QWEEEE123124234_AC_C123_V45_S67_M89"
    };
    int x;

    for (x = 0; x < sizeof samples / sizeof *samples; ++x)
    {
        int values[4] = {0};

        if (MatchCvsmPattern(samples[x], values))
        {
            printf("%d: C=%-4dV=%-4dS=%-4dM=%-4d\n", 
                x, values[0], values[1], values[2], values[3]);
        }
    }

    return 0;
}

You said that the values are at the end, so I put extra tests in there to make sure any matching pattern is the last thing in the string. If your way works then it works. Mine is just another way. :)

Tom Gunn 1,164 Practically a Master Poster

This is what sscanf was born to do:

#include <stdio.h>

int main()
{
    const char *p = "TAGNAME_C123_V45_S67_M89";
    int c, v, s, m;

    if (sscanf(p, "%*[^_]_C%d_V%d_S%d_M%d", &c, &v, &s, &m) == 4)
    {
        printf("C=%d\nV=%d\nS=%d\nM=%d\n", c, v, s, m);
    }

    return 0;
}
Tom Gunn 1,164 Practically a Master Poster

You could probably dig around and figure out what the problem is, but an easy first step is to reinstall/repair Visual Studio. Make sure the installation is clean before doing any crazy troubleshooting. It could just be a corrupt DLL or two. :)

Tom Gunn 1,164 Practically a Master Poster

That looks like generated C++/CLI code. None of that fancy stuff will work under the oldSyntax setting. You have to start with an empty project and build it manually, I think. Or find a tutorial that covers the new syntax. The MSDN library has example code in multiple langauges for all of the classes in System::IO and they are up to date for the framework version. C++/CLI is always included from what I've seen. For example.

Tom Gunn 1,164 Practically a Master Poster

The tutorial tells you what to do to compile as Managed C++ instead of C++/CLI:

Note In Visual C++ 2005, you must add the common language runtime support compiler option (/clr:oldSyntax) to successfully compile the previous code sample as Managed C++. To add the common language runtime support compiler option, follow these steps:

  1. Click Project, and then click ProjectName Properties.
    Note ProjectName is a placeholder for the name of the project.
  2. Expand Configuration Properties, and then click General.
  3. In the right pane, click to select Common Language Runtime Support, Old Syntax (/clr:oldSyntax) in the Common Language Runtime support project settings.
  4. Click Apply, and then click OK.

For more information about common language runtime support compiler options, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx (http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx)

Tom Gunn 1,164 Practically a Master Poster

Not if you define z as I did above. Are you defining z as the total number of numbers? I wasn't, but maybe the OP was.

You're the only one who started talking about z. The OP only wanted x and y. x is the total count of random numbers, y is the count of numbers in each group. The number of groups is calculated by x/y.

I'm defining z as the number of groups, just as you did. But all it does is make the logic more complex. You have to validate z, then you have to add extra tests to make sure that partial groups don't get lost, or that too many numbers don't get printed because you rely on z. That extra work is pointless when simple logic using x and y does the job:

int i = 0,
    j = 0;

while (true)
{
    cout << lo + rand() % (hi - lo);

    if (++i == x)
    {
        cout << '\n';
        break;
    }
    else if (++j == y)
    {
        cout << '\n';
        j = 0;
    }
    else cout << ',';
}
Tom Gunn 1,164 Practically a Master Poster

I don't expect you to do the work

I mean no offense, but a lot of people around here are going to stop helping you if you don't show your code soon. It's easy to post code and prove that you are trying. It's not so easy to convince everyone that you're not looking for a free ride without proof.

you don't need my code for that, because I don't know how to display that.

niek_e's examples do what you want. If you can't get them to work, show your code and someone can help you fix the problem.

Tom Gunn 1,164 Practically a Master Poster

If you are getting errors, then you have some code, right? Somebody can help you fix them if you show the code and say what the errors are.

Tom Gunn 1,164 Practically a Master Poster

Is there a 'z' involved, as in the total number of groups?

z can be calculated using x and y, but having an actual z makes it harder to handle an x that isn't perfectly divisible by y.

jephthah commented: Bork Bork Bork +12
Tom Gunn 1,164 Practically a Master Poster

How huge is huge? What problem are you having?

Tom Gunn 1,164 Practically a Master Poster

Ah so that's why %.2f wont work for scanf...

I had a lot of trouble with scanf and printf before I found out that they're not mirror images of each other. scanf doesn't use the same format string rules as printf because they have different needs and restrictions.

Anyway this a good example but its gonna make my nose bleed...
I'll try to understand this one...

Don't forget to ask questions if you need help understanding it. :)

Tom Gunn 1,164 Practically a Master Poster

Assembly::GetExecutingAssembly()->Location; will give you the full path of the running program. The 'file date' isn't specific enough. Do you want the creation time, the last read, last write? But the File class has that stuff:

String^ path = Assembly::GetExecutingAssembly()->Location;
DateTime^ fileDate = File::GetCreationTime(path);
Tom Gunn 1,164 Practically a Master Poster

c++ textbook says it's fine to allocate arrays using "new".

Yeah, that's fine. What's not fine is allocating an array using new[] , then freeing it using delete :

int *p = new int[10]; // ok
delete p; // undefined. need to use delete[]

int *p = new int; // ok
delete[] p // undefined. need to use delete

int *p = new int[10]; // ok
delete p; // undefined. need to use delete[]. probably a memory leak
delete[] p; // undefined. calling delete twice

Tests show that i will not crash so that is not correct.

Testing only shows what will happen for that run. Undefined behavior can work fine one time, crash another, and send rude emails to your boss another, all without changing anything. Instead of asking what will happen, just don't invoke UB.

Tom Gunn 1,164 Practically a Master Poster

I generates undefined behavior. new goes with delete and new[] goes with delete[] , you can't mix them. But in practice it will cause a memory leak for the first delete, and probably also a crash when you try to delete the second time.

Tom Gunn 1,164 Practically a Master Poster
return *output;

That line is really the whole problem. *output is not a pointer to char, it's a char. You're also trying to return a pointer to a local array. When the function returns, the local array goes bye bye and you can't use a pointer to it anymore.

Try passing the temporary array in as a parameter and return it at the end. That way you don't have to worry about it going out of scope:

char *extract(char output[11], int *pos, char *array) {
    int max = *pos + 10, 
        count = 0;

    while (*pos != max) {
        output[count] = array[*pos];
        count++;
        (*pos)++;
    }

    return output;
}

int pos = 0;
char *string = "BlahBlahBlahBlahBlahBlah......";
char output[11] = {0};

puts(extract(output, &pos, string));
puts(extract(output, &pos, string));
Hiroshe commented: Lots of help. Thanks +2
Tom Gunn 1,164 Practically a Master Poster

Take the pattern out of it and do a simple triangle:

F
FF
FFF
FFFF
FFFFF
FFFFFF

You can add another variable that counts down without changing how the loops work in the triangle code:

for x = 1 to 6
    for y = 0 to x
        print 'F'
    print '\n'
for x = 1 to 6
    c = 'F'
    for y = 0 to x
        print c
        c = c - 1
    print '\n'

Try to take your problems and break them apart into smaller problems and you can see how to do things easier. :)

Tom Gunn 1,164 Practically a Master Poster

No, you blurted it out in response to Hiroshe's first suggestion without waiting for the OP to ask more questions.

My post was for both of them, and anyone else reading the thread. I've learned from people who went the extra mile before and now I'm sharing the wealth.

Why not nicely pack in a parcel with automatic installers and send him on his postal address with a Project website built?

If they're still confused, then your "advanced" answer is high and dry in the land of "huh?, wtf"

And he can ask questions. That's how it works in most places. See something you don't understand, ask about it, get an answer, and learn. But here it's all about never giving away 'trade secrets' and assuming that everyone who isn't a bitter old guru is a thieving plagiarist scumbag. :icon_rolleyes:

jephthah commented: taking back some points for being completely obtuse. -2
Tom Gunn 1,164 Practically a Master Poster

I see the OP got their wish by successive approximation without having to put in any more effort.

Congrats to all :icon_rolleyes:

If the code is already there, you might as well help make it better and hope the guy learns something instead of sitting on your arse waiting for him to fail at life.

Tom Gunn 1,164 Practically a Master Poster

Tutorials only go so far. You need a good book and a comprehensive reference.

Tom Gunn 1,164 Practically a Master Poster

A few more improvements to the fixed code.

#include <stdio.h>
#include <stdlib.h>

/* constants should be centralized */
#define PESO 13.170025
#define USD  0.07593

void clear(FILE *strm)
{
    int c;

    do c = getchar(); while (c != '\n' && c != EOF);
}

int main()
{
    /* double is usually a better choice than float */
    double amount;
    int choice;

    /* long strings can be broken down to avoid multiple printfs */
    /* if you don't print '\n', flush the stream */
    printf("1) USD to PESO\n"
           "2) PESO to USD\n"
           "> ");
    fflush(stdout);

    /* check input for failure */
    if (scanf("%d", &choice) != 1)
    {
        fputs("Bad input\n", stderr);
        return EXIT_FAILURE;
    }

    /* consolidate code to avoid redundancy */
    /* if you don't print '\n', flush the stream */
    printf("Enter the amount: ");
    fflush(stdout);

    /* check input for failure */
    if (scanf("%lf", &amount) != 1)
    {
        fputs("Bad input\n", stderr);
        return EXIT_FAILURE;
    }

    if (choice == 1)
    {
        printf("%gUSD == %gPESO\n", amount, amount * PESO);
    }
    else
    {
        printf("%gPESO == %gUSD\n", amount, amount * USD);
    }

    clear(stdin);
    fputs("Press <Enter> to continue...", stderr);
    getchar();

    return EXIT_SUCCESS;
}

Also there is no need for the %.2f thing, %f will do.

The %.2f thing won't work for scanf, it's only for formatting output in printf. For printf, currency converters usually stop at the 0s for precision, so %g is a better choice than %f. %f will print the maximum precision all of the time, even if it's all 0s.

WaltP commented: We don't fix people's problems for them. We HELP them fix it themselves -4
Tom Gunn 1,164 Practically a Master Poster

use string stream in general and use atoi if speed is an issue.

That's close to my advice. But I say use strtol because atoi doesn't have any error handling capability. Boost:lexical_cast and Boost::numeric_cast are even simpler than ad hoc string stream code or robust strtol code, but you have to have Boost to use them.

Tom Gunn 1,164 Practically a Master Poster

It's hard to help you fix your code if you don't show it. ;)

Tom Gunn 1,164 Practically a Master Poster

search is a standard name declared in the <algorithm> header. It's a very bad idea to use standard names even if you don't include the header because other standard headers could include it. Try capitalizing your class from search to Search, or put it in a namespace.

Tom Gunn 1,164 Practically a Master Poster

I would just add more bits to the format if that's possible:

139 <tab> 1 <tab> 0 <tab> 0 <tab> 0 <tab> 1 <tab> 0 <tab> 1 <tab> 1 <\n>

You can extract the bits of a value like this:

#include <stdio.h>

void ExtractBits(unsigned long value, 
                 unsigned char bits[],
                 int sz)
{
    int x, y = 0;

    for (x = sz - 1; x >= 0; --x)
    {
        bits[y++] = ((value >> x) & 1) ? 1 : 0;
    }
}

int main()
{
    unsigned char bits[8];
    int x;

    ExtractBits(139, bits, 8);
    for (x = 0; x < 8; ++x) printf("%c", bits[x] + '0');
    puts("");

    return 0;
}
Tom Gunn 1,164 Practically a Master Poster

There is still a problem. Your format only allows 5 bits, but the value has 8.

Tom Gunn 1,164 Practically a Master Poster

I need to write these to a binary file and in binary values (139 = 00110001).

139 in binary is 10001011. Are you using a different way of encoding the value as binary? I can show you how to get the bits of a value, but that won't help if you're limited to 6 bits and the binary string is different from the actual bits of the value.

Tom Gunn 1,164 Practically a Master Poster
while (tryanother = 'y'){
if (tryanother = 'n')

The equality operator is ==. The = operator is for assignment. Those two conditions are the same as these:

while ((tryanother = 'y') != 0){
if ((tryanother = 'n') != 0)
Tom Gunn 1,164 Practically a Master Poster

you need memset() to set a default value.

memset() is not needed. You can do it without calling a function by using an initializer for the array:

int array[4][2] = {0}; /* init all elements to 0 */
Hiroshe commented: thanks +2
Tom Gunn 1,164 Practically a Master Poster

This is the essence of what you're doing:

#include <iostream>

using namespace std;

int main()
{
    int *p[10];
    int val = 5;

    for (int x = 0; x < 10; ++x) p[x] = &val;
    for (int x = 0; x < 10; ++x) cout << *p[x] << '\n';
    val = 10;
    for (int x = 0; x < 10; ++x) cout << *p[x] << '\n';
}

The pointers in the vector all point to the same array because the pointer is copied into the vector and not the array itself. A way to fix the problem is to have a vector of vectors and then create a new vector from the array when you want to push_back.