Results 1 to 7 of 7
Can stdio.h not be used in C programming in Ubuntu Linux? It is throwing error that no such file or directory, referring to stdio.h
This, I know is very silly ...
- 03-31-2009 #1Just Joined!
- Join Date
- Mar 2009
- Location
- Hyderabad
- Posts
- 4
C Programming in Ubuntu Linux
Can stdio.h not be used in C programming in Ubuntu Linux? It is throwing error that no such file or directory, referring to stdio.h
This, I know is very silly doubt, I've also done many programs on UNIX OS, but I'm new to Ubuntu.
I'll be happy if someone helps at the earliest.
- 03-31-2009 #2Registered Linux user #270181
TechieMoe's Tech Rants
- 03-31-2009 #3Just Joined!
- Join Date
- Mar 2009
- Location
- Hyderabad
- Posts
- 4
Hi,
I'm putting my code here...
#include<stdio.h>
main()
{
int i,n,sum=0;
printf("Enter the value of n");
scanf("%d",&n);
if(fork()==0)
{
for(i=0;i<n;i=i+2)
{
sum=sum+i;
}
printf("\n Even sum is %d",sum);
}
else
{
if(fork()==0)
{
for(i=1;i<n;i=i+2)
{
sum=sum+i;
}
printf("\n Odd sum is %d",sum);
}
}
}
- 03-31-2009 #4
The first thing I notice is your MAIN() function should return a value. Even if it's just void, it should have a return value before it. In C++ the convention is to have it return an INT.
Also, in order to use the FORK() method I think you also need to include the unistd.h header.Code:int main(){ . . . return 0; }
Code:#include <unistd.h>
Registered Linux user #270181
TechieMoe's Tech Rants
- 03-31-2009 #5Just Joined!
- Join Date
- Mar 2009
- Location
- Hyderabad
- Posts
- 4
These are the errors shown in the terminal even if I correct the things you have mentioned...
fork.c:1:18: error: stdio.h: No such file or directory
fork.c:2:19: error: unistd.h: No such file or directory
fork.c: In function ‘main’:
fork.c:6: warning: incompatible implicit declaration of built-in function ‘printf’
fork.c:7: warning: incompatible implicit declaration of built-in function ‘scanf’
- 03-31-2009 #6
Have you installed GCC on your machine? Ubuntu doesn't come with the proper programming libraries by default. Try running this command:
Code:sudo apt-get install build-essential
Registered Linux user #270181
TechieMoe's Tech Rants
- 03-31-2009 #7Just Joined!
- Join Date
- Mar 2009
- Location
- Hyderabad
- Posts
- 4


Reply With Quote
