LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C Programming question (https://www.linuxquestions.org/questions/programming-9/c-programming-question-726830/)

chibi2666 05-18-2009 12:46 PM

C Programming question
 
Hello,


I am new to C and wanted to ask what functions would I use if I wanted to force an integer tp print out 5 or 6?

rweaver 05-18-2009 12:52 PM

Quote:

Originally Posted by chibi2666 (Post 3544874)
Hello,


I am new to C and wanted to ask what functions would I use if I wanted to force an integer tp print out 5 or 6?

Variables don't print anything, and I'm not sure exactly what you're asking. You might want to look at some basic C tutorials.

PTrenholme 05-18-2009 01:31 PM

Also, if you use a int type for your variable, then that variable will be represented as a signed integer. The size of the integer you can represent is determined by your processor's "word size," typically 32 or 64 bits. Again, typically, the left-most bit represents the sign of the integer, so, for example, a 32-bit processor can represent any integer between -(2^31) and (2^31) in a single word.

If, on the other hand, you're asking about creating a visual symbol on a page or screen to represent the internal binary value as, e.g., a character string of decimal digits, look at the printf command, and read the "formatting" section. (E.g., run man 3 printf)

<edit>
Note: The above comments are quite general. The actual internal representation of int, short int, long int, negative values, etc., will depend of the specifics of the compiler you're using and the specific CPU for which you're compiling your C code.
</edit>

Alien_Hominid 05-18-2009 01:34 PM

Just use printf("%c", symbol_decimal_value_in_ASCII_table);

cloud9repo 05-18-2009 02:33 PM

Quote:

Originally Posted by chibi2666 (Post 3544874)
Hello,


I am new to C and wanted to ask what functions would I use if I wanted to force an integer tp print out 5 or 6?

spelling errors will throw a program entireley.

to print five or six is simply addition

PTrenholme 05-19-2009 12:00 PM

Quote:

Originally Posted by cloud9repo (Post 3544975)
spelling errors will throw a program entireley.

to print five or six is simply addition

Don't be silly: To print 5 or 6 would be printf("%d\n", 5 | 6); although why the OP would want to print that is an open question.

It is, in general, kinder to note that English is not the native language of the majority of the world's population and to try to understand what the OP is trying to ask rather than throwing (figuratively speaking) bricks at their head.

wje_lq 05-19-2009 01:30 PM

Quote:

Originally Posted by PTrenholme (Post 3545970)
Don't be silly: To print 5 or 6 would be printf("%d\n", 5 | 6);

Not necessarily. This is also a valid answer:
Code:

printf("%d\n", 5 || 6);

Sergei Steshenko 05-19-2009 01:56 PM

Rather than guessing what the OP meant one should have asked him/here about the real intent.

"As is" the opening post makes not much sense - a variable can have just one value at any given time, so printing 5 or 6 doesn't make much sense to me.

wje_lq 05-19-2009 03:20 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3546112)
Rather than guessing what the OP meant one should have asked him/here about the real intent.

That question was implicit in the first reply of this thread.

cloud9repo 05-19-2009 06:00 PM

Quote:

Originally Posted by chibi2666 (Post 3544874)
Hello,


I am new to C and wanted to ask what functions would I use if I wanted to force an integer tp print out 5 or 6?

tp++, tp=5
for (i=1, printf(%d, " "), tp
i=1+1
STOP
:

will print 5 then 6 to CRT.

Sergei Steshenko 05-19-2009 06:20 PM

Quote:

Originally Posted by cloud9repo (Post 3546305)
tp++, tp=5
for (i=1, printf(%d, " "), tp
i=1+1
STOP
:

will print 5 then 6 to CRT.

Have you tried to compile your code ?

Alien_Hominid 05-19-2009 11:16 PM

Quote:

Originally Posted by cloud9repo (Post 3546305)
tp++, tp=5
for (i=1, printf(%d, " "), tp
i=1+1
STOP
:

will print 5 then 6 to CRT.

This is neither C, nor some other language.

cloud9repo 05-20-2009 06:07 AM

buy a book.

wje_lq 05-20-2009 09:09 AM

Quote:

Originally Posted by cloud9repo (Post 3546822)
buy a book.

Or google this:
Code:

C tutorial
This is one of my favorites.


All times are GMT -5. The time now is 01:15 AM.