Questions tagged [conversion-specifier]

41 questions
49
votes
6 answers

Reading in double values with scanf in c

I try to read-in 2 values using scanf() in C, but the values the system writes into memory are not equal to my entered values. Here is the code: double a,b; printf("--------\n"); //seperate lines scanf("%ld",&a); printf("--------\n");…
user1880009
  • 503
  • 1
  • 4
  • 5
4
votes
2 answers

sscanf(s, "%u", &v) matching signed integers

After Cppcheck was complaining about "%u" as the wrong format specifier to scan into an int variable, I changed the format into "%d", but when having a second look on it before committing the change, I thought that the intention could be to prevent…
Wolf
  • 8,482
  • 7
  • 48
  • 92
4
votes
3 answers

What is exactly an "invalid conversion specification"?

As per C11, chapter §7.21.6.1, P9 If a conversion specification is invalid, the behavior is undefined.282) If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined. Till time, my…
Sourav Ghosh
  • 127,934
  • 16
  • 167
  • 234
3
votes
3 answers

sscanf check doesn't work when given more input than required

I have an if statement that is supposed to check if the user entered exactly 4 arguments separated by a var like the following: param1,param2,param3,param4 . Problem is that it doesn't return an error if the user gives more than 4 inputs. It only…
MM1
  • 856
  • 1
  • 6
  • 20
3
votes
1 answer

String format in C %*s

I saw somewhere a portion of code in C char name[51]; int group = 0; scanf("%*s %50s %*s %d", name, &group); printf("%s / %d\n", name, group); If we introduce "Name:Smith Group:7" it waits for us to introduce another values. It's strange. What…
user11193267
3
votes
2 answers

What is the difference between the %PRId and %d format characters?

Consider the following code: #include #include void main(void) { int32_t a = 44; fprintf(stdout, "%d\n", a); fprintf(stdout, "%"PRId32"\n", a); } When is it better to use %d and when would it be better to use…
user7659542
1
vote
3 answers

How to create a char* substring of a char* string in C?

I want to create a substring, which I see online everywhere and it makes sense. However, is there any way to, instead of outputting to a regular array of characters, output the substring as a char* array? This is the idea of my code: char *str =…
Ryan237
  • 13
  • 2
1
vote
1 answer

variable is not being evaluated and skips if statement c

I have a question. When I try to ask a user to enter yes or no as a single character and set the char variable with brackets as I either get that Y or y is not valid in my if statement. If I do it without brackets I only get the ascii value which…
Jose Ortiz
  • 579
  • 1
  • 7
  • 16
1
vote
3 answers

Having error:invalid type argument of unary '*" (have 'int')

This is my first question on here and im still learning c, and i was writing this code to enter details of a user bank account to file and reading all records back from file, when the error, error:invalid type argument of unary '*" (have 'int')…
silvercen
  • 13
  • 3
1
vote
1 answer

Taking character into array and printing it in C

I was interested in the following problem: Take the colors as characters (for example : 'y' for yellow, 'r' for red etc.) into an array and display the same. While displaying there should be a single space between each characters. So to do this I…
1
vote
1 answer

C language printf add additional useless message

I tried to simulate the linux file permission use st_mode, but when I print the result, it has an additional unwanted message. /* file permission */ char buf[9] = {0}; char tmp_buf[] = "rwxrwxrwx"; int i; for(i = 0; i < 9; i++) { if…
1
vote
1 answer

Why don't use msg in printing instead of msg[pointer -1]?

It is printing correctly but I have confusion that whenever I write just msg, it gives me Your ?@ and whenever I write msg[option-1], it gives me full message of Your name is bilal. I am not understanding the cause of [option-1]. Why it is used and…
Bilal Khan
  • 39
  • 7
1
vote
1 answer

Tracking Multiple Google Analytics Conversions

For our recruiting website we have unique urls for each of our employees connected to their employee numbers. Then they are able to give out their unique URL to their personalized page. Wanting to know if there is an easy/best way to track how many…
1
vote
1 answer

I have written a code to convert from Celisius to Fahrenheit but the output is too huge

The code is: #include #include int main() { double C, F; printf("Enter the temperature in Celisius: "); scanf("%f", &C); F = 32 + (C * (180.0 / 100.0)); printf("%f C = %f F\n", C, F); system("pause"); …
Ambitions
  • 1,729
  • 2
  • 8
  • 21
1
vote
2 answers

Creating new conversion specifier in Python

In python we have conversion specifier like '{0!s}'.format(10) which prints '10' How can I make my own conversion specifiers like '{0!d}'.format(4561321) which print integers in following format 4,561,321 Or converts it into binary…
lordzuko
  • 663
  • 10
  • 20
1
2 3