I must be going insane. This is incredibly simple so I am apparently overlooking something:
Here is my code:
int salesarray[20];
scanf("%d",&sales_input);
printf("sales_input is %d",sales_input);
salesarray[i] = sales_input;
printf("salesValue is %d",i,salesarray[i]);
Here is what I will see:
sales_input is 2salesV...
Hello,
I'm trying to print characters in the console at specified coordinates. Up to now I have been using the very ugly printf("\033[%d;%dH%s\n", 2, 2, "str"); But I just had to ask whether C++ had any other way of doing this. The problem is not even that it's ugly, the problem comes up when I try to make myself a prettier function lik...
I would like to use printf to diplay text on a serial port of an ARM microcontroller. I am unable to do so. Any help is appreciated.
My init_serial looks like this
void init_serial (void)
{
PINSEL0 = 0x00050000; /* Enable RXD1 TxD1 */
U1LCR = 0x00000083; /*8 bits, 1 Stop bit */
U1DLL = 0x000000C2; /*9600 Baud Rate @12MHz VPB Clock */
...
I'm trying to add an actual percent sign into a printf statement in Java and I'm getting the error:
lab1.java:166: illegal escape character
System.out.printf("%s\t%s\t%1.2f\%\t%1.2f\%\n",ID,pattern,support,confidence);
^
lab1.java:166: illegal escape character
...
Why does printf not flush after the call unless a newline is in the format string? (in C)
Is this POSIX behavior?
How might I have printf immediately flush every time?
Thanks,
Chenz
...
Hi, I'm trying to write a function that accepts a variable number of parameters like printf, does some stuff, then passes the variable list to printf. I'm not sure how to do this, because it seems like it would have to push them onto the stack.
Something approximately like this
http://pastie.org/694844
#include <stdio.h>
#include <st...
$cc a.c
$./a.out < inpfilename
I want to print inpfilename on stdout.
How do I do that ?
Thanks for the help in advance...
...
struct DummyStruct{
unsigned long long std;
int type;
};
DummyStruct d;
d.std = 100;
d.type = 10;
/// buggy printf, unsigned long long to int conversion is buggy.
printf("%d,%d\n",d.std, d.type); // OUTPUT: 0,100
printf("%d,%d\n", d.type, d.std); // OUTPUT: 10,100
printf("%lld,%d\n",d.std, d.type); // OUTPUT: 100,10
...
I have the following statement:
printf("name: %s\targs: %s\tvalue %d\tarraysize %d\n", sp->name, sp->args, sp->value, sp->arraysize);
I want to break it up. I tried the following but it doesn't work.
printf("name: %s\t
args: %s\t
value %d\t
arraysize %d\n",
sp->name,
sp->args,
sp->value,
sp->arraysize);
How can I break it up?
...
String formatting expressions:
'This is %d %s example!' % (1, 'nice')
String formatting method calls:
'This is {0} {1} example!'.format(1, 'nice')
I personally prefer the method calls (second example) for readability but since it is new, there is some chance that one or the other of these may become deprecated over time. Which do y...
So, I have a value of type __be16 (2 bytes). In hex, the value is represented as 0x0800 or 2048 in decimal. (16^2 * 8)
So, when I printf this; I do this:
printf("%04X", value); //__be16 value;
//Print a hex value of at least 4 characters, no padding.
output:
0008
printf("%i", value); //Print an integer.
ou...
I know this is wrong and gcc will give you a warning about it, but why does it work (i.e. the numbers are printed correctly, with some rounding difference)?
int main() {
float *f = (float*) malloc(sizeof(float));
*f = 123.456;
printf("%f\n", *f);
printf("%f\n", f);
return 0;
}
Edit:
Yes, I'm using gcc with a 32-bit mach...
if wanted to make a this method print using zero pad how do you do so
int month, day;
public void printNumeric()
{
System.out.printf("month +"/" +day +" \n");
// i would like the month if it is 5 to be 05 same thing with the day
}
...
Has anybody got any ideas on this one?
When we run:
printf("%.0f", 40.5)
On a windows box the return is "41" but on our production ubuntu server we're getting "40"
...
I have an array of 12 numbers
int ary2[] = {3,5,9,11,15,18,22,23,30,31,35,39};
I want to print the numbers out with 2 places for the number and a space between the numbers.
Example print out would be :
3 5 9 11 15 18 22 23 30 31 35 39
This is how far I got.
for(int i = 0; i < ary2.length; i++)
{
System.out.printf("%-3s"...
I have this printf statement:
printf("name: %s\t"
"args: %s\t"
"value %d\t"
"arraysize %d\t"
"scope %d\n",
sp->name,
sp->args,
sp->value,
sp->arraysize,
sp->scope);
It's inside a for loop, so it's printing multiple lines for a list of pointers.
The proble...
Using printf to print "\4unix\5lancs\2ac\2uk\0" I find, instead of a print in the form of ♦unix♣lancs☻ac☻uk, I get garbage (♫ ,►E¦§Qh ↕).
I cannot find an explanation for this; I use the following method to tokenise a string:
/**
* Encode the passed string into a string as defined in the RFC.
*/
char * encodeString(char *string) {
...
Hi there. I have some code to add fractions.
#include <stdio.h>
#include <stdlib.h>
struct frac
{
int enumerator;
int denominator;
};
typedef struct frac frac_t;
frac_t *Add(frac_t *b1, frac_t *b2)
{
frac_t rfrac;
frac_t *p;
p = &rfrac;
(*p).enumerator= ((*b1).enumerator* (*b2).denominator) + ((*b2).enumerator* (*b1).d...
How do you escape the % sign when using printf in C?
printf("hello\%"); /* not like this */
...
First and foremost, apologies for any cross-posting. Hope I'm not repeating an issue here, but I was unable to find this elsewhere (via Google and Stack Overflow).
Here's the gist of the error. If I call printf, sprintf or fprintf anywhere within my code, to display a float, I get a SIGSEGV (EXC_BAD_ACCESS) error. Let me give an example...