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
#include <stdio.h>
int main()
{
int i,l,n;
int w[1000];
int h[1000];
scanf ("%d",&l);
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d",&w[i],&h[i]);
}
for(i=0;i<n;i++)
{
if((w[i]<l)!!(h[i]<l))
printf("UPLOAD ANOTHER\n");
else(w[i]>=l&&h[i]>=l)
{
if(w[i]==h[i])
printf("ACCEPTED\n");
else
printf ("CROP IT\n");
}
}
return 0;
}
As I am new to coding these lines of code showing me error :-
In function 'main':
18:20: error: expected ')' before '!' token
21:11: error: expected ';' before '{' token
In the first IF statement, you are using !! as OR, but you should be using ||.
Compilers can not know what you are trying to do, but they can tell you what they are expecting based on what they have read so far. Because you used !!, which is the NOT symbol (twice), the compiler only knows that your expression is syntactically incorrect. In this case, it is saying that given this unexpected unary NOT operator, the current expression should have been closed with a ')' symbol.
Compilers are not mind readers, so they cannot know that you meant || (logical OR). Some compilers used to try to guess (and even fix) such typos, and they only made things worse. PL/1 comes to mind, it would attempt to fix compiler errors and this drove people crazy.
The second error on line 21 is because you placed an expression after the "else" which makes no sense to the compiler which is expecting a statement to execute at this point. You can fix this by replacing "else" with "else if". This works because IF is a statement, and that statement expects an expression next. I think this is what you intended:
#include <stdio.h>
int main()
{
int i,l,n;
int w[1000];
int h[1000];
scanf ("%d",&l);
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d",&w[i],&h[i]);
}
for(i=0;i<n;i++)
{
if((w[i]<l)||(h[i]<l))
printf("UPLOAD ANOTHER\n");
else if (w[i]>=l&&h[i]>=l)
{
if(w[i]==h[i])
printf("ACCEPTED\n");
else
printf ("CROP IT\n");
}
}
return 0;
}
Once you get more experience with C, you will recognise this kind of error easily, a simple typo can confused the compiler. Good luck!
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
I'm quite new to programming and I'm trying to make a simple program with a loop:
#include <stdio.h>
int a = 5;
int b = 0;
int main(void)
{
for (int i = 0; i < a, i++)
{
b++;
}
printf("%i", b);
}
However, when I try to compile I get the errors: relational comparison result unused [-Werror,-Wunused-comparison] and expected ';' in 'for' statement specifier for line 8. I've tried to look at several different sources on how to construct for loops and I just can't see what I'm doing wrong. Any help would be much appreciated.
Here's an example where you can practice interpreting the error statement. As you'll see, it says expected ';' in 'for' statement specificer. That's saying there's a place where you should have a semi-colon but you don't.
In your casse, there should be a semi-colon after the i < a. Right now, you have a comma.
I think you are using , instead of ; in the for loop after the statement.
for (int i = 0; i < a; i++)
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
The top curly brace under int main(void) is what keeps getting flagged. The curly-brace cannot be the real issue because I know the entire code needs to be in between the curly braces, so it must be something else. I have tried deleting and replacing the braces, I have checked the other code to make sure all the loops have braces as needed... I don't get it. I have gone out and back int the program a few times over several days.
Here is the part of my code near the error message:
# include <cs50.h>
int main(void);
{
int h;
// prompt user until user enters an integer from 1 to 8
do
{
h = get_int("hight: \n");
}
while (h < 1 || h > 8);
You have a semicolon on
int main(void);
Remove the semicolon and you should be golden.
int main(void) {
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
I don't know why cannot compile simple project below by dev.
error: Project1.exe has stopped working.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int n,d;
while(1){
printf("enter number");
scanf("%d",n);
d=n%10;
while(d!=0){
n=n/10;
printf("%d",d);
d=n%10;
}
}
return 0;
}
For one, your project does compile, since you get a run time error.
The run time error occurs because you are not using scanf correctly. The arguments to scanf after the format string should be pointers to the variables.
I don't know which compiler you are using, but any fairly modern compiler would have given you compiler warnings about this, e.g. here's Clang's output:
apa.c:9:20: warning: format specifies type 'int *' but the argument has type 'int' [-Wformat]
scanf("%d",n);
~~ ^
Changing this into scanf("%d",&n); makes your program work.
https://linux.die.net/man/3/scanf
First, the error that you got is not a compile, it's a run time error.
Second, it's happen when the run arrive to the line of scanf. This function required the variavbles address to put the value in.
Replace this:
scanf("%d", n);
With this:
scanf("%d", &n);
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
void functionality()
{
int ll = 5
char x = 'A';
for (int i = 0; i < ll; i++)
{
printf("c ", x);
}
}
I am learning C language and I wrote the above snippet. However, it is not running with loads of errors. I cannot seem to find the problem of what is happening here since I followed the code from a tutorial and I have double checked everything.
int main()
{
printf(functionality);
}
on the first glance of your code I can see 3 problems:
the line int ll = 5 is missing a ;
AND
the line printf("c ", x); should be printf("%c ", x);
AND
a missing } at the end
For next time, try to also provide the error codes, please.
The main function should look like this:
int main(){
functionality();
}
The function is void, hence no need to call it in a print statement. Also, we call a function by first stating the name of the function followed by the curly braces. I suggest that you first familiarize yourself with the basic syntax of the language first.
These errors are not unknown:
There is no main function, so there's nothing to run.
You are missing a closing } at the end of this function.
You are missing a ; at the end of int ll = 5;
Your printf call is malformed, Did you want printf("%c ", x);?
Where is your #include <stdio.h> (or does your compiler bring that in automatically?).
you are missing a ; at the end of the line int ll=5
change the c to %c in the printf() function as follows
printf("%c",x);
also make sure you close all the braces properly at the end of the function.
make sure you have a main function in your program,and also include header files
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
hello=) with this following code i get the exception
error: expected ‘;’ before ‘printf’
#include <stdlib.h>
#include <stdio.h>
int main() {
int i;
scanf("%i", &i);
for(int i=0 ; i<10; i++){
if(i==1) printf("one");
else if(i==2) printf("two");
else if(i==3) printf("three");
else if(i==4)printf("four");
else if(i==5)printf("five");
else if(i==6) printf("six");
else if(i==7) printf("seven");
else if(i==8)printf("eight");
else(i>9) printf("even"+"/n"+"odd");
}
return 0;
}
Can i sum up this code into a sorter form ? And why do i get this exeption?
thank you all
Add some brackets "{}".
Code will looks better and will work.
if(expression) {
} elseif(expression) {
} elseif(expression) {
} else {
}
PS. I know it will better. If this text be comment. But I don't have points reputation yet :(
PS2. #Myst if code will have 9. Code don't printf anything.
else clause can't have a condition. So, you either mean just else or else if (i>9).
Besides, C doesn't have + operator that concatenates strings. You can just leave out the + and the C preprocessor will concatenate adjacent string literals (see C11, 5.1.1.2, 6).
else if(i>9) printf("even" "/n" "odd");