Problem in opening a file!


 
Thread Tools Search this Thread
Top Forums Programming Problem in opening a file!
# 1  
Old 10-25-2009
Problem in opening a file!

Hello All,
I am new to programming in unix.
I am trying to create a file by using open command. The entire file is :

Code:
#include<fcntl.h>
main(void){
int fd;
fd = open("File1", O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR|S_IRWXO);
printf("%d ", fd);
}

The problem I am facing a strange problem. When I execute the above file (using gcc), I dont see File1 getting created! But if I change the filename with any other name (say File2), I am able to get create the file!

Could anyone pls tell me what could be happening?

Regards,
karthik

Last edited by pludi; 10-26-2009 at 09:55 AM.. Reason: code tags, please...
# 2  
Old 10-26-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 3  
Old 02-26-2010
Bug Opening problem

Dear Friend,

Your code in correct. But you need to include the necessary header files.

I ran your code. It is not working. It showed me some error. After that I include the some header files. Then your code is working fine.

Code:
#include<stdio.h>
#include<fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

main(void){
        int fd;
        fd = open("File1", O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR|S_IRWXO);
        printf("%d ", fd);
}

You need to include above two header files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Opening a file in vi and automatically save and quit this file using shell script

Hi friends, In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script. the code segment is: ------------------------------------------------------------ cd ~/netfpga/projects/scone/sw/... (2 Replies)
Discussion started by: sachinteotia
2 Replies

2. Shell Programming and Scripting

Xmllint - Xml-file problem --ods file not opening

Dear All, this is my first post on this Forum, glad to be here. I'm trying to fix an .ods file. Yes, I had a backup, but it's also corrupted. When opening the document I get this EM: read error format error discovered in the file in sub-document content.xml at 2,337040(row,col). So I... (3 Replies)
Discussion started by: jameslast
3 Replies

3. Shell Programming and Scripting

Problem with grep opening a file

Hello All, Here is my silly question on grep.. Here is my code.. DAY=$(date --date="yesterday" +%y.%m.%d) check "grep -h ' 404 ' /home/sathya/SystemOut.log /home/sathya/SystemOut_${DAY}*.log " Where check is alias which makes to run this command in all my Servers. When I execute... (3 Replies)
Discussion started by: sathyaonnuix
3 Replies

4. UNIX for Dummies Questions & Answers

Problem in opening UNIX file in Windows

Hi , I am having file in unix with size (386796649) , below is the output of ls command in UNIX. I have ftp'ed the file to my windows machine . When i tried to open the file it is not opening . Why it is so . Is there is size limit. -rw-rw-rw- 1 p10 pQQ 98473 Sep 17 17:20... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

5. IP Networking

problem opening TCP ports

Please can somebody help me. I'm trying to open ports 999, 1982 and 1983 but am not having much luck. I used iptables -A INPUT -i eth0 -p tcp --sport 999 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A INPUT -i eth0 -p tcp --sport 1982 -m state --state NEW,ESTABLISHED -j ACCEPT iptables... (5 Replies)
Discussion started by: thehaapyappy
5 Replies

6. Shell Programming and Scripting

Getting Following problem when opening shell script (Very Urgent)

Hi All, Actually when i am trying to open my shell script file 1.sh then i am getting the following error. > vi 1.sh "/var/tmp/ExdNaarK" No space left on device Can anybody tell me that how to rectify it. It is very urgent. Because i am not able to do any work due to the above error. ... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies

7. UNIX for Advanced & Expert Users

Problem Opening X-Clients in Solaris

Hi, I use hummingbird exceed9.0 to open active X-Server Sessions to Solaris(Sol9 SPARC) machines. I m able to open "Solaris desktops(CDE)" for all Solaris machines except a specific machine. Initially the XDMCP display manager chooser did not display (that) server in the list. I had to... (2 Replies)
Discussion started by: mahatma
2 Replies

8. AIX

Problem opening port 9998

Hi there, I have been trying to open port 9998 on an AIX 5.1 box to no avail. This machine is not connected to the internet and I have only been accessing it locally, so I know it's not a network firewall/proxy issue. I have tried editing /etc/services and inetd.conf, refreshing inetd.conf, and... (3 Replies)
Discussion started by: erica057
3 Replies

9. UNIX for Advanced & Expert Users

timeout opening writing control channel /dev/initctl problem occur i cant shoudown

Hi... This is message that occurs when i am trying to shutdown the linux system timeout opening writing control channel /dev/initctl how can i shutdown what is the problem here.. Thanks in advance ... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

10. UNIX for Dummies Questions & Answers

opening a file

im trying to open a file in my bin directory and the farthest i can get is into the folder but not the actual file itself i use text edit as the editor. when i try to open the file it says it doesn't exist here is what i type cd bin open cmnds (dir. which it is under) open test no such... (4 Replies)
Discussion started by: hiei
4 Replies
Login or Register to Ask a Question