format-specifiers

Why Conversion Specification %lf does not work for Double in printf

蹲街弑〆低调 提交于 2019-11-30 16:45:08
I am writing a very small code just scanf and printf . I am reading a double value and printing it. The conversion specification %lf works properly to read a double value. But, it doesn't work with printf. When I am trying to print that value I am getting output like 0.000000 double fag; scanf("%lf", &fag); printf("%lf", fag); But, if I use %f in printf it works properly. cremno The C standard library implementation you're using doesn't conform to C99 (or newer). The changes listed in the foreword (paragraph 5) contain: %lf conversion specifier allowed in printf The description of the l length

What does an asterisk in a scanf format specifier mean? [duplicate]

喜你入骨 提交于 2019-11-30 10:52:40
This question already has an answer here: What is the difference between %*c%c and %c as a format specifier to scanf? 3 answers So I stumbled across this code and I haven't been able to figure out what the purpose of it is, or how it works: int word_count; scanf("%d%*c", &word_count); My first thought was that %*d was referencing a char pointer or disallowing word_count from taking char variables. Can someone please shed some light on this? *c means, that a char will be read but won't be assigned, for example for the input "30a" it will assign 30 to word_count , but 'a' will be ignored. The *

Why Conversion Specification %lf does not work for Double in printf

穿精又带淫゛_ 提交于 2019-11-29 23:59:40
问题 I am writing a very small code just scanf and printf . I am reading a double value and printing it. The conversion specification %lf works properly to read a double value. But, it doesn't work with printf. When I am trying to print that value I am getting output like 0.000000 double fag; scanf("%lf", &fag); printf("%lf", fag); But, if I use %f in printf it works properly. 回答1: The C standard library implementation you're using doesn't conform to C99 (or newer). The changes listed in the

%p Format specifier in c

梦想的初衷 提交于 2019-11-29 17:23:01
问题 How are the specifiers %p and %Fp working in the following code? void main() { int i=85; printf("%p %Fp",i,i); getch(); } I am getting the o/p as 0000000000000055 0000000000000055 回答1: If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal. In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number

What does an asterisk in a scanf format specifier mean? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-11-29 16:03:26
问题 This question already has answers here : What is the difference between %*c%c and %c as a format specifier to scanf? (3 answers) Closed 3 years ago . So I stumbled across this code and I haven't been able to figure out what the purpose of it is, or how it works: int word_count; scanf("%d%*c", &word_count); My first thought was that %*d was referencing a char pointer or disallowing word_count from taking char variables. Can someone please shed some light on this? 回答1: *c means, that a char

How Do I Parse a Date Time String That Includes Fractional Time?

做~自己de王妃 提交于 2019-11-29 15:14:17
I have a date time string: 20:48:01.469 UTC MAR 31 2016 I would like to convert this string representation of time to a struct tm using strptime , but my format string isn't working. Is there a format specifier for fractional seconds? Perhaps %S , %s , or something else? Code snippet is below: tm tmbuf; const char *str = "20:48:01.469 UTC MAR 31 2016" const char *fmt = "%H:%M:%s %Z %b %d %Y"; strptime(str,fmt,&tmbuf); Using this free, open source C++11/14 library , here is another way to deal with parsing fractional seconds: #include "tz.h" #include <iostream> #include <sstream> int main() {

Usage of void pointers across different platforms

孤街浪徒 提交于 2019-11-29 09:22:53
I have heard that pointers should first be cast to void to ensure consistency of values across different platforms and should use %p format specifier. Why is it and what exactly are the problems? int x=100; int *pi=&x; printf("value of pi is: %p",(void*)pi); Mohit Jain printf is a variadic function and must be passed arguments of the right types. The standard says %p takes void * . Implicit cast doesn't take place for variadic functions . Quoting from N1570 7.21.6.1 The fprintf function p : The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing

Why weren't new (bit width specific) printf() format option strings adoped as part of C99?

允我心安 提交于 2019-11-28 23:19:16
While researching how to do cross-platform printf() format strings in C (that is, taking into account the number of bits I expect each integer argument to printf() should be) I ran across this section of the Wikipedia article on printf() . The article discusses non-standard options that can be passed to printf() format strings, such as (what seems to be a Microsoft-specific extension): printf("%I32d\n", my32bitInt); It goes on to state that: ISO C99 includes the inttypes.h header file that includes a number of macros for use in platform-independent printf coding. ... and then lists a set of

printf not yielding input values

…衆ロ難τιáo~ 提交于 2019-11-28 14:53:21
I have the following block of code. The final line is meant to yield the values for X , Y and P values that are input by the user. However it only returns (0,0,0) instead of the values given by user. What am I missing? printf("What is the robot's initial X position? (cm)\n"); scanf("%f",&X); printf("What is the robot's initial Y position? (cm)\n"); scanf("%f",&Y); printf("What is the robot's initial angular position? (degrees)\n"); scanf("%f",&P); printf("The initial position is (%d, %d, %d)\n", X,Y,P); Assuming X , Y and P are of type double or float ( input part , scanf() ), you need to use

Scanning with %c or %s

余生颓废 提交于 2019-11-28 14:52:41
I had to do a program for college in which I should separate, between a certain amount of people, those who liked and the ones who disliked something. so I did this: char like[100]; printf("Like? Y or N \n"); scanf ("%c", like); The program compiled, but didn't work the way it should. The user was not able to write "y or n" when asked "Like?" So I tried this: char like[100]; printf("Like? Y or N \n"); scanf ("%s", like); And it worked. But I don't know why it worked. Can somebody please explain me the difference between %c and %s in a scanf ? First, please do some basic research before coming