Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6938127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:27:11+00:00 2026-05-27T12:27:11+00:00

I tried both creat and open system call. Both working in the same way

  • 0

I tried both creat and open system call. Both working in the same way and I can’t predict the difference among them. I read the man page. It shows “Open can open device special files, but creat cannot create them”. I dont understand what is a special file.

Here is my code,

I am trying to read/write the file using creat system call.

#include<stdio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
int main()
{
 int fd;
 int written;
 int bytes_read;
 char buf[]="Hello! Everybody";
 char out[10];
 printf("Buffer String : %s\n",buf);
 fd=creat("output",S_IRWXU);
 if( -1 == fd)
 {
  perror("\nError opening output file");
  exit(0);
 }

 written=write(fd,buf,5);
 if( -1 == written)
 {
  perror("\nFile Write Error");
  exit(0);
 }
 close(fd);
 fd=creat("output",S_IRWXU);

 if( -1 == fd)
 {
  perror("\nfile read error\n");
  exit(0);
 }
 bytes_read=read(fd,out,20);
 printf("\n-->%s\n",out);
 return 0;
}

I expted the content “Hello” to printed in the file “output”. The file created successfully. But content is empty

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:27:12+00:00Added an answer on May 27, 2026 at 12:27 pm

    The creat function creates files, but can not open existing file. If using creat on an existing file, the file will be truncated and can only be written to. To quote from the Linux manual page:

    creat() is equivalent to open() with flags equal to O_CREAT|O_WRONLY|O_TRUNC.

    As for device special files, those are all the files in the /dev folder. It’s simply a way of communicating with a device through normal read/write/ioctl calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Grails 1.2.x (Tried both 1.2.0 and 1.2.2- same behavior) I am
I've tried asp.net and jsp...and the programming language was powerful enough to create both
I tried both JRSwizzle, and MethodSwizzle. They compile fine on the simulator but throw
I've tried both of the following: repo init -u git://android.git.kernel.org/platform/manifest.git -b android-2.1 repo init
I created a simple test with SendKeys, and tried both SendWait and Send. Private
I tried using both ReadProcessMemory() and WriteProcessMemory() in my application,but in both cases I
I've tried this both with and without the 'ExceptionType' parameter. I have an Error.aspx
I've tried various editors, both desktop applications and web-based RTEs, but have not found
I have tried setting a line-height for sIFR3 in both the sifr-config.js and my
I've tried msysGit and Git on Cygwin. Both work just fine in and of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.