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

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");
}

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.

Redirection ambiguity [duplicate]

This question already has answers here:
printf anomaly after "fork()"
(3 answers)
Closed 4 years ago.
I have a file named test.c (Its contents are given below)
#include <stdio.h>
#include <unistd.h>
int main()
{
printf("T\n");
fork();
printf("F\n");
}
The expected result is:
T
F
F
Compiling with gcc and executing ./a.out ,the output is:
T
F
F
which matches the expected answer.
But ambiguity arises when I redirect the output to another file.
$ ./a.out > Output.txt
The Output.txt has the following data:
T
F
T
F
Why is there an additional T in my Output.txt file when I use redirectors?
1) I've check this in multiple PC's running on ubuntu with gcc installed.
2) Tried deleting the Output.txt and moving all the files to a different location, but this still persists.
P.s. this works fine without the redirector.
I think it's because of the buffer, give a try with the follow code:
#include <stdio.h>
#include <unistd.h>
int main() {
printf("T\n");
fflush(stdout);
fork();
printf("F\n");
}

syntax error near unexpected token [duplicate]

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

gcc: fatal error: regex.h: No such file or directory [duplicate]

This question already has an answer here:
Regex.h for windows
(1 answer)
Closed 4 years ago.
For my C programs, I am using gcc.
Ultimately, I want to write a program that does stuff with regular expressions. Right now, however, my program simply outputs Hello World:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <regex.h>
int main(void) {
printf("Hello World\n", regex);
return 0;
}
Here's how I compiled that program:
gcc -std=c99 -o helloWorld helloWorld.c
That produces this error:
fatal error: regex.h: No such file or directory
I'm a C newbie. Any help would be much appreciated.
See what happens if you drop .h from regex.h

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