LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-27-2016, 05:00 PM   #1
thiagofw
Member
 
Registered: Jul 2016
Location: Minas Gerais, Brazil
Distribution: Slackware 14.2
Posts: 42

Rep: Reputation: Disabled
Talking Tatto.c : Problem compilation


Code:
#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.

Last edited by thiagofw; 12-27-2016 at 05:59 PM.
 
Old 12-27-2016, 11:15 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Change every == into =
Even then, the code won't make sense, but it might compile. Ignore the ccompiler-warnings
 
Old 12-28-2016, 12:02 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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.
 
Old 12-28-2016, 04:12 AM   #4
thiagofw
Member
 
Registered: Jul 2016
Location: Minas Gerais, Brazil
Distribution: Slackware 14.2
Posts: 42

Original Poster
Rep: Reputation: Disabled
Talking

Quote:
Originally Posted by NevemTeve View Post
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 View Post
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
 
Old 12-28-2016, 04:41 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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...
 
Old 12-28-2016, 04:54 AM   #6
thiagofw
Member
 
Registered: Jul 2016
Location: Minas Gerais, Brazil
Distribution: Slackware 14.2
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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;
}
 
Old 12-28-2016, 05:01 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
= is assignment, == is comparison.
You ought to use == in while.
and also there was a () missing:
while ((Love = Life) && (Love = Gabriel))
 
Old 12-28-2016, 05:26 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> I made substitutions and still did not spin.

I didn't know it was supposed to 'spin'. In the Original Post, the body of the while-loop was empty anyways.
 
Old 12-28-2016, 05:30 AM   #9
thiagofw
Member
 
Registered: Jul 2016
Location: Minas Gerais, Brazil
Distribution: Slackware 14.2
Posts: 42

Original Poster
Rep: Reputation: Disabled
It worked, it's compiling without errors.
But would not he have to display the message?


Quote:
#include <stdio.h>
int Love, Gabriel, Life;

int main ()
{
Love = Gabriel;
Gabriel = Life;
Life = Love;
while ((Love = Life) && (Love = Gabriel))
{
printf("Testing...");
}

return 0;
}
 
Old 12-28-2016, 05:59 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
Old 12-28-2016, 06:10 AM   #11
thiagofw
Member
 
Registered: Jul 2016
Location: Minas Gerais, Brazil
Distribution: Slackware 14.2
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compilation problem Nagat Linux - Newbie 2 04-17-2012 02:01 PM
compilation problem rania kamal Linux - General 1 09-28-2008 01:57 AM
compilation problem shariefbe Linux - Software 6 08-18-2008 09:12 AM
compilation problem lamtab Linux - Newbie 5 11-12-2007 05:28 PM
compilation problem girish_hilage AIX 3 05-31-2006 08:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration