This question already has answers here:
How can I print a quotation mark in C?
(9 answers)
Closed 4 months ago.
How to print " in printf("something equal "x(as char)" ") ??
#include <stdio.h>
int main(void) {
printf("something equal \"x(as char)\" ");
return 0;
}
In C, the escape character is \.
So to print a literal ", instead of using it to end a string, use \".
Related
This question already has answers here:
Return value of printf() function in C
(13 answers)
How do I explain the output of this simple C code?
(4 answers)
Explain the return value of printf [duplicate]
(3 answers)
Closed 1 year ago.
When I run this code without \n the output is hello5 but with \n the output is hello6, can someone explain?
#include <stdio.h>
//Compiler version gcc 6.3.0
int main()
{
int c;
c = printf("hello\n");
printf("%d",c);
return 0;
}
The printf function returns the total number of characters printed.
When you print "hello\n", that's 6 characters, so c is 6. When you print "hello", that's 5 characters, so c is 5.
This question already has answers here:
What is the effect of trailing white space in a scanf() format string?
(4 answers)
problems with scanf("%d\n",&i) [duplicate]
(3 answers)
Closed 4 years ago.
If \n is not there the program accepts 5 and if \n is used in scanning then the programs asks for 6 inputs.
#include<stdio.h>
int main()
{
int marks[5];
int i;
for(i=0;i<5;i++)
{
scanf("%d\n",&marks[i]);
}
for(i=0;i<5;i++)
{
printf("the element at %d is %d\n",i,marks[i]);
}
return 0;
}
This question already has answers here:
This program sounds the bell!
(13 answers)
Closed 5 years ago.
I've just come across this:
#include <stdio.h>
int main() {
printf(" \a ");
}
and the output isn't " \a " as expected. Does anybody know why?
The '\a' in an escaped representation of the BEL charcater which has ascii code 7.
The \ is used to "escape" a character that otherwise has no representation and cannot be written in a string by other means. Another examples are the newline '\n' and carriage return '\r'.
Characters starting with a backslash \ are called escape sequences, these are special and aren't printed out. In this case, \a is the sequence for a bell ring.
This question already has answers here:
scanf() only sign and number
(2 answers)
Closed 7 years ago.
I need to parse input like this: "+ 704"
Into: switcher = "+" and c = 749
I got this:
scanf("%c %d", &switcher, &c);
This does not work.
Scanf returns 1 instead of 2, c = 4196080 and printf("%c", switcher) prints a newline.
What am i missing?
So basically, there's a newline waiting on the buffer. To get rid of it, simply add one space to the beginning of your formatting string.
scanf(" %c %d", &switcher, &c);
This question already has answers here:
Why is "a" != "a" in C?
(11 answers)
Closed 7 years ago.
Given below is a piece of code that does not do what I want
do
{
printf("inserisci un nome: ");
scanf("%29s", s);
} while (s!="*");
My aim is to exit from the cycle if the string entered is "*".
Why doesn't it work?
What should I modify?
Take a look at strcmp to compare strings, != will not do what you want.
In that case != will compare the variable s (a pointer to the first element of the array s) with the string "*". That is why it was not working properly.