Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Location
    Hyderabad
    Posts
    4

    Question 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.

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by mkausal View Post
    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.
    STDIO.H is an ANSI-standard header file that works on all operating systems that support ANSI. That includes the big three: Windows, Mac OS and Linux. If you're getting an error on your import it's a code problem. Post your code and we'll do what we can to help you.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Location
    Hyderabad
    Posts
    4
    Quote Originally Posted by techieMoe View Post
    STDIO.H is an ANSI-standard header file that works on all operating systems that support ANSI. That includes the big three: Windows, Mac OS and Linux. If you're getting an error on your import it's a code problem. Post your code and we'll do what we can to help you.
    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);
    }
    }
    }

  4. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    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.

    Code:
    int main(){
    . . .
    
    return 0;
    }
    Also, in order to use the FORK() method I think you also need to include the unistd.h header.

    Code:
    #include <unistd.h>
    Registered Linux user #270181
    TechieMoe's Tech Rants

  5. #5
    Just Joined!
    Join Date
    Mar 2009
    Location
    Hyderabad
    Posts
    4
    Quote Originally Posted by techieMoe View Post
    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.

    Code:
    int main(){
    . . .
    
    return 0;
    }
    Also, in order to use the FORK() method I think you also need to include the unistd.h header.

    Code:
    #include <unistd.h>
    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’

  6. #6
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    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

  7. #7
    Just Joined!
    Join Date
    Mar 2009
    Location
    Hyderabad
    Posts
    4
    Quote Originally Posted by techieMoe View Post
    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
    Thanks for the information, i thought gcc would be installed by default. I'll try and check. Bye..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...