ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include <stdio.h>
int Love, Life, Gabriel;
main()
{
Love==Gabriel;
Gabriel==Life;
Life=Love;
while (Life == Love = Gabriel = true);
{
printf ("Gabriel my life, my love!");
}
return 0;
}
I am trying to make this basic code in C.
What he wanted was what he displays a sentence above, the problem is that he knows little of C and faces constant errors.
Can someone help me?
Yes, this is a tattoo in honor of my son.
Even with obvious errors fixed, it is not at all clear how you want the program to behave.
If you only want it to display the sentence and exit as stated, there is no need for the while loop or any of the integer variables. But as you do have those in the code I suspect that you want it to print the sentence some number of times, then exit.
It would be helpful if you could describe in more detail how you want it to work, and what the variables are supposed to be used for, then we can help you get it working.
Change every == into =
Even then, the code won't make sense, but it might compile. Ignore the ccompiler-warnings
I made substitutions and still did not spin.
Quote:
Originally Posted by astrogeek
Even with obvious errors fixed, it is not at all clear how you want the program to behave.
If you only want it to display the sentence and exit as stated, there is no need for the while loop or any of the integer variables. But as you do have those in the code I suspect that you want it to print the sentence some number of times, then exit.
It would be helpful if you could describe in more detail how you want it to work, and what the variables are supposed to be used for, then we can help you get it working.
Well, since 2008 I have contributed with linux, but I got lost in the C language just when I needed it most.
I decided to pay homage to my son, and I tried to make it a tatoo.
The int> Love, Life and Gabriel variables are merely illustrative, to give something more to the code.
I thought of making an infinite loop, because my love for him is infinite.
So I tried to say:
While Life is equal love and love equals Gabriel, write: "Gabriel my love, Gabriel my life".
The intention was to make an infinite loop, and that the code if compiled would really show the output.
In a few words, a simple code more functional with these variables, love, life, gabriel.
Thanks
hm.
At first none of these variables were initialized, which means they will have random values.
Love==Gabriel will return true or false depending on the two variables (if they are equal to each other). (the result is not used)
Life=Love is an assignment, Life will contain the same value as Love.
Quote:
While Life is equal love and love equals Gabriel
in your implementation the and is missing:
while (Life == Love) && ( Love == Gabriel )
finally would be nice to post what kind of errors happened...
hm.
At first none of these variables were initialized, which means they will have random values.
Love==Gabriel will return true or false depending on the two variables (if they are equal to each other). (the result is not used)
Life=Love is an assignment, Life will contain the same value as Love.
in your implementation the and is missing:
while (Life == Love) && ( Love == Gabriel )
finally would be nice to post what kind of errors happened...
With the modified code:
Code:
#include <stdio.h>
int Love, Gabriel, Life;
int main ()
{
Love = Gabriel;
Gabriel = Life;
Life = Love;
while (Love = Gabriel = Life)
{
printf("Testing...");
}
return 0;
}
bash-4.3$ gcc tattoo.c -o program
bash-4.3$ ./program # No result No print message.
bash-4.3$
New code:
bash-4.3$ gcc tattoo.c -o programs
tattoo.c: In function 'main':
tattoo.c:9:24: error: expected identifier before '(' token
while (Love = Life) && (Love = Gabriel)
^
bash-4.3$
Code:
#include <stdio.h>
int Love, Gabriel, Life;
int main ()
{
Love = Gabriel;
Gabriel = Life;
Life = Love;
while (Love = Life) && (Love = Gabriel)
{
printf("Testing...");
}
return 0;
}
as I tried to explain, at the beginning of your code Love, Gabriel and Life have random values (or at least you did not specify any value).
It looks like they are automatically set to 0 in your case, and that is equal to the logical false.If you move your declarations into main{} they will get another value.
That's why the while loop will never be executed:
while ((Love = 0) && (Love = 0))
will set Love to 0 - twice - and also evaluated as false (0).
You ought to use == for comparison.
as I tried to explain, at the beginning of your code Love, Gabriel and Life have random values (or at least you did not specify any value).
It looks like they are automatically set to 0 in your case, and that is equal to the logical false.If you move your declarations into main{} they will get another value.
That's why the while loop will never be executed:
while ((Love = 0) && (Love = 0))
will set Love to 0 - twice - and also evaluated as false (0).
You ought to use == for comparison.
Yes.. sorry
It worked, now entered into an eternal loop.
When I did send the image of how it was.
My thanks to you pan64 and all the friends of linuxquestions.
I promise to learn more so I can help as well as help me.
Thank you
Code:
#include <stdio.h>
int Love, Gabriel, Life;
int main ()
{
Love == Gabriel;
Gabriel == Life;
Life == Love;
while ((Love == Life) && (Love == Gabriel))
{
printf("Gabriel meu amor, minha vida...");
}
return 0;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.