This question already has an answer here:
Keep getting this compiling error [closed]
(1 answer)
Closed 9 years ago.
When I complile, I keep getting this error.
mario.c:11:14: error: expected expression
while (n=<0);
^
I've tried changing things and then fixing them and changing other things and then fixing those but nothing seems to help. I'm new at this. Can anyone help?
do
{
n = GetInt();
}
while (n=<0);
=< is invalid syntax; you want <=, like this:
do
{
n = GetInt();
}
while (n<=0);
Related
This question already has answers here:
How dangerous is it to access an array out of bounds?
(12 answers)
Closed 2 years ago.
I can't figure out where the problem is in my program?
#include <stdio.h>
int main()
{
int a[2][2]={{1,2},{3,4}};
printf("The value of a[2][1] is %d",a[2][1]);
return(0);
}
I expected the answer to be 3, it's actually wow! 32765 wait! what!? I'm pretty confused.
Can someone help?
You don't have anything in the spot a[2][1]. I think what you meant to put is a[1][0]. Remember that the index starts at 0 not at 1.
The reason why you are getting that big number is because that number was already sitting there in that memory location. It has nothing to do with the array you created.
This question already has answers here:
string comparison inside if condition malfunctioning [duplicate]
(2 answers)
Closed 6 years ago.
I am trying to implement an IF STATEMENT
in my C-Server.
read(client_fd,received_data,100);
printf("%s",received_data);
I want to print "ooo" if the received data equals to "test"
if (received_data == "test") {
printf('ooo');
}
?
The above example results in errors. (can't compile)
I don't know much C.
UPDATE :
Now I can compile fine ( after changing 'ooo' to "ooo" )
But although I am sending "test" to it.. if statement is not doing anything i think.
The == doesn't work for const char *.
Use strcmp instead.
This question already has answers here:
Uses of C comma operator [duplicate]
(20 answers)
How does comma operator work during assignment?
(5 answers)
Closed 9 years ago.
This funny thing happened when I make a mistake .
I what write :
int i;
i = 1;
but it is
int i ;i = 1 ,23;(I guess sometime I click the middle button of my mouse) .
Then I compiled the program by gcc and it went through without any warning or error!
And after I notice that . I try int i = 1,23; , and now the compile give a error:
error: expected identifier or ‘(’ before numeric constant
So ,Why the first time compile suceessful ?
And why it give me a error the second time?
What exactly ", 23" means?
Thanks in advance.
This question already has answers here:
Is uninitialized data behavior well specified?
(7 answers)
What will be the value of uninitialized variable? [duplicate]
(6 answers)
Closed 8 years ago.
Please explain why I am getting output 2 here. My expected o/p is 5 or 7. Please throw some light. Thank you!
#include<stdio.h>
typedef enum {a=3, b, c, d, j}e;
void f(e *e1) {
printf("%ld", (int)*e1);
}
main(){
e es;
f(&es);
}
You haven't initialized es, so your program is just printing the random value that happens to be on the stack when the program runs.
You need to say something like:
e es = c;
That will give you the 5 output you seek.
This question already has answers here:
C conditional operator ('?') with empty second parameter [duplicate]
(6 answers)
Closed 9 years ago.
#include<stdio.h>
int main()
{
printf("%d\n", 4 ?: 8);
}
According to the C standard this program is invalid because it is missing an expression between the ? and :.But The interesting thing is that there is when I compile the code it is printing 4.how come it will print 4 rather than showing any compile error
This is a gcc extension.
x ? : y
is equivalent to
x ? x : y
See here for detail.