Syntax error using pointer

Asked

Viewed 104 times

-2

int main() {
    char const* path = "/bla/bla";
    struct zip *teste;
    int *errorp;
    &teste   = *zip_open(path, ZIP_CREATE, errorp);
    return 0;
}

It returns this error:

main.cpp: In function ‘int main()’:
main.cpp:11:50: error: lvalue required as left operand of assignment
     &teste   = *zip_open(path, ZIP_CREATE, errorp);

I guess it’s because I’m not assigning anything to errorp but does it need to save exactly? when I assign a number to it from the conversion error.

I am following that documentation.

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site

1 answer

4

I have two things to tell you: first you are programming in C and not C++, and this is worrying, you are making a basic mistake, so it would not be the case to learn the mechanisms of language before learning to do something more complex?

That’s how it works:

int main() {
    char const* path = "/bla/bla";
    int *errorp;
    struct zip *teste = zip_open(path, ZIP_CREATE, errorp);
}

I put in the Github for future reference.

The function call syntax is completely wrong, I can’t imagine why you put the & and *, in it.

There is at least another problem visible in this code that will soften the execution (does not allocate memory to errorp), and something tells me that’s not even how you use this library, so solving this problem will do little good. The problem described is solved.

  • I did this because the examples I found on the internet used this code, I prefer to learn by doing more complex things, so learning doesn’t get boring, and in my question I leave the doubt about the variable errorp, the way you did, it returns an error saying you need a reference to "zip_open", so I used "&", now if you don’t know how this library works, how can your answer contribute to the question?

  • 3

    They don’t use it that way because this syntax doesn’t exist and copying an example from the Internet without understanding what is happening there is not programming or learning to program. If you think you learn to program in the correct annoying way then my suggestion is to look for an activity that pleases you more. I’m sorry to tell you this, but you’re not learning to code, you’re just trying to make a code compile and eventually run something. I answered what you asked that is a syntax error, you did not ask how to use the library.

  • Buddy, everyone has their own way of learning, I don’t need another activity, my dream is to be a programmer and I’ll get whatever you think, Thanks for nothing.

  • 3

    Good luck, you’ll need.

  • 1

    @Maniero, I liked your answer. It, in fact, partially solves the problem presented in the question. However, unfortunately, I consider your defense that there is a correct way to learn a programming language, as well as I consider inappropriate your suggestion that people who do not adapt to this correct way should look for something that pleases them more.

  • 4

    @v.Santos ok. I also do not agree with a negative in response that is said to be right, so it negatively responded by the comment. You don’t seem coherent. Nor does it seem coherent to say that there must be other different ways of doing something, but considered that only its form is the right one and as my way of thinking is wrong I deserved a punishment. It’s also not coherent because I didn’t say that there are no other ways to learn, I said that this way is wrong, 35 years ago I do this and I saw many people trying to learn in various ways, this one had 0 people successfully in all this time.

  • 4

    But I think that everyone has the right to learn the way they want, at no point do I forbid anyone to do the way I know it doesn’t work, because who will suffer all the bad consequences of the bad decision is herself, so she can do it, I just try to show that there’s a better way, I try to help, no one is forced to accept help and can break their face on their own, I just hope they don’t say I didn’t warn them. Nor does it make sense to say what is inappropriate when I even said what was said there.

  • 4

    What I said was that if you find it boring to learn how to program, you better give up the profession because it’s full of boring stuff all the time. I don’t want to deceive anyone, I don’t want to make people who want fun things think that programming is like that. It is at some point, but it is full of boring stuff too and it is good to get used to it. The text is too short to make this inference you made. But people can be incoherent, even if they just disagree without making arguments, even if they’re not actually in the scope here.

  • 4

    "I want to learn, but only with something that I agree" - this is intellectual suicide in any area, plus a countersense by nature (take advantage who wants).

  • 2

    I would say that Maneiro’s comment should be valid even for other alleged professionals, such as doctors, lawyers, "servants", etc. A lot of things end up badly done because the person is in an area solely for the supposed profits that will get and not for the real interest, I’m not talking about passion for that, but about understanding, learning and executing technically and perfecting, there are many people who do stupid courses (even imbeciles) and believe they are perfecting themselves, when in fact they are just filling sausages. Personally I believe it is valid to say that certain forms of doing lead to problems.

  • @Guilhermenascimento the problem is that he doesn’t even know the methodology I use for study and he’s already kicking something he doesn’t even know, he may have 400 years of experience, he’s not God, a correct method to study and learn doesn’t exist, and the way I’ve been studying so far has helped me a lot.

  • 2

    Dear @Zaque understand your annoyance, I try to imagine myself out here to understand, of course the feeling is only yours, but I’ve been in similar place, really thinking like this, I’ve suffered a lot to study, at a time when the best internet we had was 2mb (10mb only rich) and 3G still seemed like a dream (we barely had 2G), today we have the easiest things, I believe it is your current scenario and I really think that Maniero has a lot of experience and restraint in what you say, and the words may even sound bad at first sight, but it was looking for people like him that I managed to tread my [...]

  • 2

    [...] path the path of the stones may get there, but it will cause too much trauma, if I were you would put on a scale imagine what it is worth, listen to someone who has experience, even if sometimes it seems (I said it seems, does not mean that it is) or hit your head in various places and problems? The choice is yours, of course, but I’m telling you, people like Maneiro, Bacco, Anderson and Jefferson (soon you’ll meet the last two) are amazing people who spend the little time you have sharing knowledge tested, logical and often presenting references/ sources. [...]

  • 2

    [...] I must say that Maniero gives lectures on technology and really you could reflect if indeed he is being hard on you, but to strengthen you and not to oppress you.

  • 1

    @That you informed your methodology: Eu fiz assim porque os exemplos que eu encontrei na internet usavam esse código, eu prefiro aprender fazendo coisas mais complexas. There is the right method to learn, there are thousands of people who are dedicated to understanding this and getting the best result and this is documented, including many of these studies are specifically for the area of computing, which has already been classified as one of the most difficult to learn (really). And some people participated in the learning of thousands of people and saw the results.

  • 1

    But unfortunately some people think that they were born knowing and that with their natural knowledge they will get somewhere and they can ignore all the knowledge created by the people who came before. It also has studies on this, but as almost nobody understands it was created a popular term, they are called Snowy Corner.

  • 3

    The tragic part is that people like that can’t get out of the vicious circle that they’ve entered because they always think that others who have experience are wrong and they who are starting out now know what is right, and spend their whole lives deluded and blaming others for their failures. I will always do my part to avoid this, even if it costs me some disaffection, is part of it. I will not omit myself. After all, it was by omission of a generation of parents that all these problems arose. I’m sorry if it bothers you, I just wanted to help.

Show 12 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.