[Solved] decimal of numbers in c

The error is that %d in the format specifier of both scanf and printf represents decimal, so it expects an int (in the case of scanf, a pointer to int) Since you are declaring b and c as float, %d in the lines scanf(“%d”,&b); printf(“%d lbs is %d kgs.”,b,c); should be changed to %f respectively. … Read more

[Solved] C: Weird conditional printf behavior [closed]

There is one semicolon after the if statement that is causing the problem. if (i!=0); { //this will always execute } change it to if (i!=0) { //this will execute if i != 0 } The compiler does not warn you because the first statement is syntactically valid. solved C: Weird conditional printf behavior [closed]

[Solved] nested calls to printf [duplicate]

You may be able to see what’s happening more clearly if you split the statement into several statements: int temp1 = printf(“Hello world!\n”); int temp2 = printf(“%d”, temp1); printf(“%d”, temp2); The first printf prints Hello world!\n. Since this is 13 characters, it returns 13. The second printf prints 13. Since this is 2 characters, it … Read more

[Solved] pointers not read correctly

i intentionally left the previous answer because understanding memory allocation is trivial in programming in c specially. and as i see you have a big issue with that. but still you have issue in nearly every thing. in my actual answer, i will try to simplify you how to use strtok, to split string and … Read more

[Solved] Please explain the difference in the printfs below

%x format specifier experts the argument to be of type unsigned int. In your case, printf(“%x\n”,(const uint8_t)0x0D); printf(“%x\n”,0x0D); arguments will be promoted (default promotion rule) to match the type, but in case of printf(“%x\n”,(const uint8_t *)0x0D); //supplying a pointer printf(“%x\n”,(uint8_t *)0x0D); //supplying a pointer You’ll invoke undefined behavior, as per C11, chapter §7.21.6.1 […] If … Read more

[Solved] How to solve segmentation error in C program [closed]

Variable base is undeclared. Variable idade is undeclared. It should be printf(“%d”,base) if your are using base. #include <stdio.h> int main(){ int age; int aget; int total; printf(“Input your age: “); scanf(“%i”, &age); printf(“Input your age two: “); scanf(“%i”, &aget); total = age + aget; printf(“%d”,total); return 0; } 1 solved How to solve segmentation … Read more

[Solved] Having trouble understanding output of line of code –

As for me then this return 0*printf(“%d”,a[i]); just a bad programming style. At least it would be better to write instead return ( printf(“%d”,a[i]), 0 ); not saying about printf(“%d”,a[i]); return 0; Maybe this statement is found in a recursive function. As for your question Having trouble understanding output of line of code – then … Read more

[Solved] problems with scanf and conversion specifiers

These are the very basics of C Programming, and I strongly advise you to get a decent book – The C Programming Language by Dennis Ritchie would be a good start. There are numerous errors in your code. A char can contain only one character, like ‘A’, or ‘a’ or something like that. When you’re … Read more

[Solved] Removing Leading Zeros within awk file [duplicate]

Try this: sub(/^0+/, “”, $2)? $ awk ‘BEGIN{b=”000000000000787301″; sub(/^0+/, “”, b); print b;}’ 787301 or typecast it by adding zero: $ awk ‘BEGIN{b=”000000000000787301″; print b+0;}’ 787301 update A working example based on comments: $ echo ‘E2EDP19001 02002000000000000797578’ | awk ‘{$2 = substr($2,6); sub(/^0+/, “”, $2); print $2;}’ 797578 or, preserve $2: $ echo ‘E2EDP19001 02002000000000000797578’ … Read more

[Solved] PHP printf adds something after formatted string

I got it. I wrote: echo printf(…); instead of just: printf(…); After string produced by printf() i got that string length, which is value returned by printf (in fact – added number was 9 in case of 123.45 value, in 20.4 case it was number 8). 2 solved PHP printf adds something after formatted string