syntax error near unexpected token [duplicate] - c

This question already has answers here:
Beginner: syntax error before int main ()
(2 answers)
Closed 5 years ago.
Tish is the program:
#include <stdio.h>
int main()
{
printf("77777");
return 0;
}
yaki#ubuntu:~/Desktop/yakima$ gcc yakima.c -o yakima.o
yaki#ubuntu:~/Desktop/yakima$ ./yakima.c
This is the error:
./yakima.c: line 3: syntax error near unexpected token `('
./yakima.c: line 3: `int main()'
What can you do with this problem?

You are trying to execute source file.
After you create object file you have to link object file(s) to binary like
gcc -c yakima.c -o yakima.o
gcc yakima.o -o yakima
and execute binary
./yakima

Related

why is it showing undefined reference to `add'? [duplicate]

This question already has answers here:
C error: undefined reference to function, but it IS defined
(6 answers)
Closed 9 months ago.
I have written a code that just basically add two numbers. file is the self made header file
named xoxo.h
extern int add(int r,int m);
This is my second file that contains the function defination of the function add.The name is
run.c
#include "xoxo.h"
int add (int i,int f) {
return (i+f);
}
This is my main file tester.c
#include "xoxo.h"
#include <stdio.h>
void main() {
printf("%d",add(1,2));
}
The error is shown as
PS C:\Users\HOME\Desktop\New folder> gcc tester.c
C:\Users\HOME\AppData\Local\Temp\ccBwWXFk.o:tester.c:(.text+0x1e):
undefined reference to `add' collect2.exe: error: ld returned 1 exit
status
plz help
When you compile the application, you need to provide run.c as well, otherwise the application cannot find the implementation of add.
Run gcc tester.c run.c instead.

Error in handling command line arguments in C [duplicate]

This question already has answers here:
How to read asterisk( * ) as an argument from the command line in C [duplicate]
(3 answers)
argv: Sanitizing wildcards
(2 answers)
Closed 4 years ago.
I am trying to write a C code that will take three arguments from the command line in the form of {num1} {operator} {num2}. It is working fine in case of all operator symbols other than *.
This is the code to verify this:
#include <stdio.h>
int main(int argc, char const *argv[]) {
printf("%d\n", argc);
}
I am compiling this as gcc test.c -o test.
Then when I run it using ./test 5 + 9, it gives the expected output 4. But then when I run ./test 5 * 9, it gives 25 as output. What am I doing wrong here?
The * is expanded by the shell into a list of all files in the current directory. If you don't want shell-expansion you need to (single) quote the argument:
./test 5 '*' 9

syntax error near unexpected token '(' in C 7 [duplicate]

This question already has an answer here:
Syntax error near unexpected token '(' when using terminal [closed]
(1 answer)
Closed 7 years ago.
I am having problem with the following code
#include <stdio.h>
int main()
{
int tall = 175;
int weight = 68;
printf("I am %d slim.\n", tall);
printf("I am %d kilogram.\n", weight);
return 0;
}
i have created these code following a course but i have an issue (The Compiler said that )
./file.c: line 3: syntax error near unexpected token `('
./file.c: line 3: `int main()'
for more information I am using GCC in linux destro ..
and i am using terminal To run ...
there's No IDE
It seems that you are not compiling your program, but that you are trying to execute it without compiling. The errors that you see is /bin/bash that tries to interpret this as shell code.

Cygwin showing error iostream.h is unable to locate [duplicate]

This question already has answers here:
fatal error: iostream.h no such file or directory [duplicate]
(3 answers)
Closed 8 years ago.
I wanted to run C programs on windows in order to achieve this I downloaded cygwin(Linux like environment for windows) made a program and kept it on a directory called ..\cygwin\home\Computer
Code goes here
#include<iostream.h>
void main(){
printf("Hai");
}
When i am trying to execute this program using command prompt.
$ g++ hai.c
Its throwing out an error
hai.c:1:21: fatal error: iostream.h: No such file or directory
#include<iostream.h>
^
compilation terminated.
What is going on any idea?
change to
#include <iostream>
#include <cstdio>
int main(){
printf("Hai");
}
or with g++ -x c hai.c or gcc hai.c
#include <stdio.h>
int main(){
printf("Hai");
}

how to use clang compile c file with math.h? [duplicate]

This question already has answers here:
Undefined reference to sqrt (or other mathematical functions)
(5 answers)
Closed 9 years ago.
#include <stdio.h>
#include <math.h>
int main()
{
printf("%.81f\n", 1+2*sqrt(3)/(5-0.1));
return 0;
}
output:
/tmp/a4-4oU730.o: In function main':
a4.c:(.text+0x4f): undefined reference tosqrt'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Try adding -lm for libm for math to your build command. That said, your code works fine for me using clang 4.1 on Mac OS.

Resources