Narue 5,707 Bad Cop Team Colleague

A nested pointer **i is the same thing as a two dimesional array int i[][] .

No, that's wrong. Though pointers can be used to simulate arrays of varying dimensions, they're not the same thing.

Narue 5,707 Bad Cop Team Colleague

what is a not flat text file?

CSV is an example of a flat file. XML is an example of a non-flat file.

Narue 5,707 Bad Cop Team Colleague

Can I use my own code that I slapped a GPL on and provided to sourceforge in my own commercial application?

What does being commercial have to do with anything? The GPL doesn't stop you from charging money, it's all (mostly) about the openness of the source code. Ideally you would use the LGPL for a library that's both open source and used in the commercial application because it's easier to draw a clean line between licenses.

In that way, does the GPL somehow relinquish my own rights to my IP?

Yes. You could use the code to a certain extent and with sufficient changes not be legally bound by the GPL, but by placing the code under the GPL you've given up your right to make a verbatim copy under closed source.

However, prior art plays a part too. If you take code from a commercial application where you own the IP and release it as a new project under the GPL (assuming you're not violating the license of the commercial application), the commercial application isn't in violation of the GPL as long as you can prove that it existed prior to the GPL release. As for taking code from the commercial project that exists in the GPL project after both exist, you'd probably need to hire a lawyer to make sure that there's a legal leg to stand on. ;)

Narue 5,707 Bad Cop Team Colleague

this is just an example..but i can't compile it.is there any mistakes in these codes?

If it doesn't compile, there are mistakes. That's axiomatic. If it doesn't compile, there are also compilation errors. Use them to fix the mistakes or post the errors so that others can help you fix the mistakes if you're incapable of doing so by yourself.

Narue 5,707 Bad Cop Team Colleague

Start by understanding the algorithm, them use your knowledge of C++ to write equivalent code.

Narue 5,707 Bad Cop Team Colleague

I don't know what happened and I'm sure that reason is scanf().

Then let's start by using scanf() correctly. When your choice variable is a short int, the correct format specifier is %hd . Fix that and return if the problem persists.

Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

If you understand, you can figure out now why I'm naming the title "nested pointer", right?

I was pretty confident that I knew why just from reading the title.

I'm thought of this "timeline" of process happen in my code...

note: see my attachment for better picture of each explanation.
 
a. '1000' assigned to "value_1"
 
b. "pointer_1" become a point to "value_1" content, where:-
        - *pointer_1 == value_1's content
        -  pointer_1 == value_1's address
 
c. "pointer_2" become a point to "pointer_1" content, where:-
        - **pointer_2 == value's content
        -  *pointer_2 == pointer's content == value_1's address
        -   pointer_2 == pointer_1's address

If I were your teacher, I'd give you perfect marks for this.

The references operator, usually known as, "& == address of"... At first, I thought the equation is literally descriptive, but then I discover I'm wrong. When this operator assigned to the pointer, it will return address to the "standard variable", but not only that, it return the whole content of the address.

Now you're getting into nonsensical territory. The address-of operator is literal. It evaluates to the address of an object, and a pointer object isn't treated differently. The problem with pointers and addresses is people get confused because a pointer is both an object with an address and an object that stores an address. So for an initialized pointer there are two addresses and two values involved:

  • &ptr : The ptr object's address.
  • ptr : The ptr object's value (the pointed-to …
mike_2000_17 commented: great +14
Narue 5,707 Bad Cop Team Colleague

Let me know, if you think its not correct.

It's not correct. Let's ignore that unistd.h isn't a standard header (you don't use anything from it anyway) and go right to the first real error. Boiled down, it looks like this:

char *no;

cin >> no;

int len = strlen(no);

First, you forgot to include <cstring> for strlen(). Second, you clearly don't understand how pointers work because an uninitialized pointer does not point to infinite memory. A pointer must be initialized to memory that your process owns before it can be used.

C++ is not just C with cin and cout, there are many more things that can make your life easier:

#include <algorithm>
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
    string line;
    
    while (true) {
        cout << "Enter a number (EOF to quit): ";
        
        if (!getline(cin, line))
            break;
        
        bool not_num = any_of(line.begin(), line.end(), [](char c) { return !isdigit(c); });
        
        cout << "'" << line << "' is" << (not_num ? " not " : " ") << "a number\n";
    }
}

Notice how you don't have to worry about pointers with the std::string class. That's one of the key benefits for people who are low level programming challenged. ;)

All of this is assuming that the need for a "number" means a series of digits rather than a value suitable for conversion to one of the integer or floating-point types. If you need to convert to a numeric type, the naive algorithm …

Narue 5,707 Bad Cop Team Colleague

my question is, why i got some error..I cant recognize such of that error...

What's the error? :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

When you encode something you have to decode it with the same username and password again, otherwise it will give you a very strange character text.

It's called symmetric key cryptography, and I don't recommend inventing your own algorithm as it's more likely to be woefully insecure than decent in any way. As one example, your key isn't unique (actually, it's VERY not unique) due to the chance of unsigned integer wrap around with arbitrarily long text strings.

We're going to use this for our website, and I thought it might be nice to share this with others!

If you're going to show it off on your website, fine. If you're doing this for fun and education, fine. If you're planning on using this algorithm for your website's security, I strongly suggest that you reconsider and instead use .NET's built-in cryptography algorithms. The following is much better (not to mention more concise):

using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

public class Program {
    public static void Main() {
        // Test driver for the Encryption class
        //
        var crypt = new Encryption("QNHMKh4HTJnTxzDsorGvL5IZxfPgvagA", "21Z8CmgIDQEB9Khm7fs8aw==");
        string cipherText = crypt.Encrypt("this is a test");
        string plainText = crypt.Decrypt(cipherText);

        Console.WriteLine("{0}\n{1}", cipherText, plainText);
    }
}

public sealed class Encryption {
    private byte[] _key; // Symmetric key used for both encryption and decryption
    private byte[] _iv;  // Initialization vector for the encryption algorithm

    /// <summary>
    /// Initialize an object of the Encryption class with specified key and IV.
    /// </summary>
    /// <param name="key">Base 64 representation …
darkagn commented: Consice answer with great coding example +10
Narue 5,707 Bad Cop Team Colleague

what am I doing wrong ?

You're using feof() as the loop condition. feof() won't return true until after a request for input from the file fails, but by then it's too late and you'll continue processing the result of failed input. Given that fgetcsv() returns false on end-of-file, you can use it directly as the loop condition and forget about feof() entirely:

while ($buffer = fgetcsv($file_handle, 4096))
{
    echo "<br>";

    ...
}
Narue 5,707 Bad Cop Team Colleague

But some companies are partners with microsoft (which I think is pathetic).

The bold part of your statement (emphasis added by me) suggests that you have a strong bias against Microsoft which is probably coloring your opinion of .NET for web development. If you hadn't called Microsoft partners pathetic then your opinion on .NET versus PHP would be more credible.

Narue 5,707 Bad Cop Team Colleague

What are you talking about? What country do you live? I thought diploma still matters today?

In the United States at least, computer science courses require a certain number of credits in higher mathematics such as calculus and linear algebra. A degree certainly helps with marketability, but it's not an absolute requirement like in many other fields.

Narue 5,707 Bad Cop Team Colleague

Should'nt this work since I am modifying only one memory location.

No, it shouldn't work because string literals aren't modifiable.

Narue 5,707 Bad Cop Team Colleague

However, now I have a problem with my looping because this way, I am seeing the last line *TWICE* in my output

This is precisely the reason why feof() shouldn't be used as the only loop condition. It only returns true after you've tried and failed to read from the stream, which means the last record will be processed twice. fgets() can be used directly as the loop condition because it returns NULL on any kind of failure (including end-of-file):

while (fgets(LineBuffer, BUFFERSIZE, infile) != NULL)
{
    printf("%s", LineBuffer);
    fprintf(outfile, "%s",  LineBuffer);
}
Narue 5,707 Bad Cop Team Colleague

If this were real code, I'd say go ahead and use goto.

If this were real code, I'd say that it should probably be refactored into multiple functions rather than straight nested conditionals. Though I can't help but notice that there's not a loop in the example cod in the first place. ;)

Narue 5,707 Bad Cop Team Colleague

Programming is rooted in mathematics, but modern programming really doesn't require any kind of advanced math except in specialized fields. Logic and problem solving are the keys to success in programming.

Narue 5,707 Bad Cop Team Colleague

Make sense why i can't use your previous suggestion?

I love how you basically changed the requirements without anyone knowing unless they reverse engineered your code from the screenshot. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

There's not always going to be a tutorial. Design the interface to suit your needs, and if it doesn't work out, throw it away and start over.

Narue 5,707 Bad Cop Team Colleague

Yeah, but i won't always know the datatype but i'll always know the data length. Hense why i developed it without using a datatype

I suspect you don't understand my suggestion, otherwise you'd realize that you don't need to know the source data type for it to work. Technically you don't even need to know the data length, but it certainly helps when accessing bytes in a way that avoids out of bounds accesses.

Narue 5,707 Bad Cop Team Colleague

Unless you need to force endianness, there's no need for bitwise operators at all. You can pun the value into an "array" of bytes with a simple cast:

#include <cstddef>
#include <iostream>

int main()
{
    int value = 3234;
    unsigned char *p = (unsigned char*)&value;
    
    for (std::size_t i = 0; i < sizeof(value); i++)
        std::cout << (int)p[i] << '\n';
}
Narue 5,707 Bad Cop Team Colleague

So i'm wondering how 162 and 12 are converted to 3234?

Don't forget that the 12 is your second byte, so it needs to be appropriately shifted: (12 << 8) | 162 == 3234 .

Narue 5,707 Bad Cop Team Colleague

i am don't know what median is ?
or strdDevition ?

Do you know what Google is?

Narue 5,707 Bad Cop Team Colleague

I want tree traversal program for given Alphabets not numbers..

You should get started writing one then. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

Narue, i am trying to do both.

The two are mutually exclusive. As for what I understand to be your plan, it's sound. Apply yourself to your chosen field (systems programming) with appropriate gusto, but also continue to broaden your skill set (eg. web, application, and mobile programming). It's counter-intuitive, but a well rounded programmer is more likely to be hired than a specialist in all but niche positions.

Narue 5,707 Bad Cop Team Colleague

So what you say it that system programmers are in less demand rather than application developers?

Of course. That should be pretty obvious.

It won`t end like this anyway, we won`t end up programming programs/applications just because they are in demand on the market.

When your belly is empty, you'll do what needs to be done to fill it. It's fine being an stubborn idealist when you're in school, but in the real world we need to be more practical.

I believe something new will be created.

I'm confused as to the point of this thread. Are you asking about your career choices or trying to encourage some sort of philosophical orgy about systems programming?

Narue 5,707 Bad Cop Team Colleague

I just want to hear from members who has experience in industry as well as students of the forum what do you think about this?

What do we think about what exactly? It comes as no surprise that the application side is growing more quickly than the systems side, and it has nothing to do with non-expert programmers grasping anything. Applications are closer to the users and thus meet business needs that change constantly. Systems are the magic that allows applications to run, but they're relatively static and there are already plenty of mature systems from which to choose.

Narue 5,707 Bad Cop Team Colleague

I notice you don't specify an encoding, which means you're using the default. Unless you changed it in Tomcat's configuration it should be compatible with C's character type, but you can force the content type to be extra safe: "Content-Type: text/xml; charset=ISO-8859-1" .

There are a number of factors at work here, so give that a go and reply if it doesn't work.

Narue 5,707 Bad Cop Team Colleague

Set your window to full screen, always on top, then disable the Windows and Alt keys so that the user can't switch applications. This solution obviously involves some system hooking for true full screen and disabling special keys, but Google can help you with those problems.

Narue 5,707 Bad Cop Team Colleague

Is it possible to know what is the undefined behavior?

Undefined behavior is by definition undefined. Anything can happen. I've heard cases of undefined behavior frying hardware, or corrupting system files, so it's far from harmless. And I suspect that's why people always look for descriptions of what might happen, they want to weigh the risks.

iamcreasy commented: Woo! +3
Narue 5,707 Bad Cop Team Colleague

What means, "only defined on output streams"?

Here's what the standard says:

#include <stdio.h>
int fflush(FILE *stream);

Description
If stream points to an output stream or an update stream in which the most recent
operation was not input, the fflush function causes any unwritten data for that stream
to be delivered to the host environment to be written to the file; otherwise, the behavior is
undefined.

Note that input streams and update streams where the most recent operation was input fall into the "otherwise" part of the definition. stdin is an input stream, so fflush(stdin) invokes undefined behavior.

Narue 5,707 Bad Cop Team Colleague

If my program doesnt use the stack or heap at all (as in me putting a new or stk()? in it) will it still have (however small) memory leaks?

If you don't create leaks, or use any libraries that create leaks, then it stands to reason that there won't be any leaks. ;)

Narue 5,707 Bad Cop Team Colleague
fflush(stdin);

Please don't do this anymore. fflush() is only defined on output streams, which means your code is subtly broken.

Narue 5,707 Bad Cop Team Colleague

Is there a simpler way to do this(less strings, without strcat)?

I'd do it more like this:

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

int main(void)
{
    char buf[BUFSIZ];
    
    printf("Enter a floating-point value: ");
    fflush(stdout);
    
    if (fgets(buf, sizeof buf, stdin) != NULL) {
        double value;
        char *end;
        
        /* Trim the newline, if any */
        buf[strcspn(buf, "\n")] = '\0';
        
        /* Validate the string, we'll also need the value later */
        value = strtod(buf, &end);
        
        if (*end == '\n' || *end == '\0') {
            char *radix = strrchr(buf, '.');
            size_t precision = 0;
            
            if (radix != NULL)
                precision = strlen(radix + 1);
            
            printf("%.*f\n", precision, value);
        }
    }
    
    return 0;
}

That's not necessarily simpler, but it's more robust.

Also, could you explain what does %.*f actually mean? I mean, * is usually used for pointers.

In a printf() format string, * is a placeholder for some part of the field width. So %*d would print an integer where the field width is specified by another argument:

// These two calls are functionally identical
printf("%5d\n", 123);
printf("%*d\n", 5, 123);

See this.

Narue 5,707 Bad Cop Team Colleague

I don't need that kind of an example because I know how to use atof.

One of your posts suggested otherwise, which is why I suppose someone posted an example for you.

I think the question is really simple.

It is really simple. The first reply gave you the steps you need to perform: "Read the number as a string. Count the decimals. Convert the string to your double."

There is no "work" here.

Then why haven't you completed it yet? :D

And also, I asked why doesn't the following code work.

You forgot to include <stdlib.h>, and you're still printing a whole floating-point value. The value needs to be formatted correctly in the printf() format string, which is why you need to count digits initially:

printf("%.*f\n", precision, a);

Otherwise you don't know what value to use for precision . This is yet another case of misunderstanding the difference between internal and display representations.

Narue 5,707 Bad Cop Team Colleague

What would happen if I (somehow) made an enum bigger than unsigned int?

The compiler will attempt to adjust the underlying type according to the largest enumerator value. As for defining an enumerator value lager than the largest possible integer, good luck trying. ;)

Narue 5,707 Bad Cop Team Colleague

Well, that is not even close.

It's an example of how to convert a string to double, which is a necessary step in the solution to your problem.

Don't expect someone to do all of your work for you.

Narue 5,707 Bad Cop Team Colleague

I've done Java for so long now that I've forgotten some of those rules.

Java has the same rule... :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

Its an assignment

Not my assignment. How about you prove that you've made an honest attempt to solve the problem before running here for "help". Otherwise I'll consider this thread in violation of Daniweb's homework rule.

Narue 5,707 Bad Cop Team Colleague

Just because you don't personally use a language doesn't make it unimportant.

/thread

Moschops commented: So true, and needs saying more often. Although this is the first time I've seen someone suggest Java as a replacement for C. +8
Narue 5,707 Bad Cop Team Colleague

C++ or C?

How is that new? If you want something new, pick a language that doesn't have the same ancestry as the ones you already know. You'll get more out of it than the same old syntax with a different standard library. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

I've been trying to make a reliable IRC client for a while now, and I know very little about sockets.

Am I the only one who finds this sentence semantically humorous? :D

How is the program to know the server will send three or four lines before I should send the NICK/USER ?

I'm not familiar with the underlying protocols specific to IRC, but have you considered a header packet with necessary bookkeeping information?

Narue 5,707 Bad Cop Team Colleague

It was a 6 year old thread may not be much help ryt?

You'll find that older threads have a tendency to show up near the top of the search hits on Google. That's one reason why we don't automatically close threads after a certain age.

Narue 5,707 Bad Cop Team Colleague

I don't understand what having or not having line 10 does except for the fact that without it my program runs without any errors.

My code is standard conforming, so I can think of two reasons:

  1. You're not using a modern compiler.
  2. The "errors" you're getting aren't really errors. Rather, you're experiencing the extra blocking read from cin.ignore() when the stream is empty. This can seem like an error if you're not expecting it.
Narue 5,707 Bad Cop Team Colleague

The output says: File does not exist or dictionary is empty...

While that might be true, you can't be sure because your code is making an assumption about why the pointer is null. Try using perror() for more detailed information:

file_ptr=fopen("C:\Dictionary","r");

if (file_ptr == NULL) {
    perror(NULL);
    return NULL;
}

However, I can safely say right now that it looks like you're trying to open a folder rather than a file. Unless "C:\Dictionary" refers to an actual file without an extension, the error will be "File not found".

Narue 5,707 Bad Cop Team Colleague

Is this compilable? (i.e without the white space)

Yes, that particular annoyance was removed in C++11. The OP's compiler (Visual C++ 2010) supports the new feature.

frogboy77 commented: Thank you. Need a new compiler. +6
Narue 5,707 Bad Cop Team Colleague

So can you please explain how to use this std::vector?

Certainly. Here's a rough facsimile of your code using std::vector:

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int a, b;
    
    cout << "Enter the size for the 2D array: ";
    
    if (cin >> a >> b) {
        vector<vector<int>> vec(a, vector<int>(b));
        int k = 0;
        
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++)
                vec[i][j] = k++;
        }
        
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++)
                cout << vec[i][j] << ' ';
                
            cout << '\n';
        }
    }
}

The only real difference is in the constructor where you need to build up both dimensions. This is the proper way to do it if you already know the sizes, but you can grow the vector dynamically as you go if necessary, that's where the real power lies:

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<vector<int>> vec;
    string line;
    
    cout << "Enter a table (EOF to finish):\n";
    
    while (getline(cin, line)) {
        // Insert a new row to the vector
        vec.push_back(vector<int>());
        
        istringstream iss(line);
        int x;
        
        while (iss >> x)
            vec.back().push_back(x);
    }
    
    for (int i = 0; i < vec.size(); i++) {
        for (int j = 0; j < vec[i].size(); j++)
            cout << vec[i][j] << ' ';
            
        cout << '\n';
    }
}
PrimePackster commented: Thank U very much. That helps a lot +0
Narue 5,707 Bad Cop Team Colleague

To my findings, on these users pages, they had zero posts, zero records just as fresh starters and i began to wonder how they ranked top on the weekly points with such figures.

Logging in and sending PMs are the usual suspects in spammer activity points.

Narue 5,707 Bad Cop Team Colleague

Why are the first three 77's not indented?

Consider the first three iterations of your loop:

cout << setw(0) << 77;
cout << setw(1) << 77;
cout << setw(2) << 77;

Now go see if you can figure out what happens when the length of the printed object meets or exceeds the set field width.