Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
can someone please tell me how to check in c that a particular letter was pressed ?
I want to check if the letter 'r' was pressed. here is a small part of my code, where I need to check if it was pressed.
ch = getch();
if(ch==r)
i=1;
else
i=2;
the program considers the 'r' in my 'if' as a variable, but I want it to be considered as a letter so I would be able to check if it was pressed. can someone please tell me how to do that ?
Put the 'r' in single quotes:
ch = getch();
if(ch=='r')
i=1;
else
i=2;
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Actually right now i am learning c and doing an excercise of looping and got messed up in a question.
my code is:
#include<stdio.h>
void main()
{
int i,j,k,spc,k;
printf("\enter the number of rows:");
scanf("%d",&rows);
spc=rows+4-1;
for(i=1;i<=rows;i++)
{
for(k=spc;k>1;k--)
{ printf(" ");
}
for(j=1;j<=i:j++)
printf("*");
printf("\n")
spc--;
}
}
https://www.w3resource.com/c-programming-exercises/for-loop/c-for-loop-exercises-14.php
and this is the reference for the answer by them whose excercise i am doing right now.
can you see any difference bw these codes.
please help me.
thank you
as i can see, you have small errors which you need to fix ,
first is, int i,j,k,spc,k;, here, 'k' is written twice, next is scanf("%d",&rows); but, rows is not declared anywhere, in this line,for(j=1;j<=i:j++), you missed a semicolon and added colon instead, so replace it with for(j=1;j<=i;j++) and the last one is, printf("\n") ,in this line, you missed a semicolon! and for the desired output, you just need to add a space in printf("*"); ,i.e, printf("* ");.Thats it.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
error: expected expression before ';' token
graph[ ptr->count ].count- ;
^
I am getting the error shown when I compile my code in Geany. Can anyone please help what to do?
Assuming you’re trying to decrement...count by 1...you need one more minus sign, like this
int i = 10;
i--;
to be a valid expression in C/C++.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
EDIT: Sorry, I accidentally submitted the question before I was done. Boy, are you guys quick!
I've been going through the second edition of The C Programming Language and noticed that the book uses broken bars instead of pipes. Was this an old notation or are they interchangeable?
Its a font problem, most of the books show it as broken pipe even though it is the pipe operator
Boolean OR operator. It will set all bits true that are true in either of both values provided.
if ( a==0 || b==3 )
if any one of these is true the "if" statement will execute because it looks for true or
false values.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
char b;
while((b=getchar()) != '.' );
{
printf("%c",b);
}
If I had the following input in stdin abcd.
it should print a then b then c then d then detect the . and terminate although its simply printing a . instead of abcd
Remove the semicolon at the end of while condition
The semicolon at the end of the while loop makes it execute only once . It does not loop at all . Your program is simple a linear program with no looping .
Otherwise your program logic is fine .
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a variable:
int a = 0x0304;
I print it out like this:
printf("the value is 0x4x\n", a);
but it shows the value is 0x304, I want the result should be the value is 0x0304, how to print it out like this?
Try adding a leading 0 to your format specifier - %04x
printf("the value is 0x%04x\n", a);
Just in case its omission from your question wasn't a typo, note that I've also added a % to make this a format specifier. As it stands, the code in your question would have just echoed the value is 0x4x