Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

fopen says file does not exist

Name: Anonymous 2010-09-27 19:38

I'm trying to make a call to fopen in C, but it says the file doesn't exist. Except it does. The file gets created during execution and I have verified that it does, in fact, get created (and it does contain what I want it to). I chmodded the file and its parent directory to 755 but that didn't help anything. Here's the code.

// wc -l ~/server/.tmp | sed 's/ .*//g' > ~/server/.wc
// line count --> erase the filename --> store in file .wc
if ((system("wc -l ~/server/.tmp | sed 's/ .*//g' > ~/server/.wc")) < 0)
{
    error("tried to wc");
}
// send the wordcount and a null
if ((fileBuf = fopen("~/server/.wc", "r")) == NULL)
{
    error("tried to open .wc");
}

error just calls a function that does perror and then exits. When it tries to open the file, it prints "tried to open .wc:  No such file or directory".

Name: Anonymous 2010-09-27 19:45

What does "~" mean to fopen? It doesn't mean shit, it's just part of a relative path

It's commonly used as an alias in shells, for the current users homedir path, but you can't use that stuff in C

Name: Anonymous 2010-09-27 19:47

I tried doing it with an absolute pathname and got the same result. /home/(myname)/server/.wc

Name: Anonymous 2010-09-27 19:51

can you stat it

Name: Anonymous 2010-09-27 19:55

Do you mean stat as in shell or stat as in the system call?

Name: Anonymous 2010-09-27 20:05

>>5
lets see if you can work out which one I meant

Name: Anonymous 2010-09-27 20:10

>>6
I'll start with the easier one, then.
$ stat .wc
  File: `.wc'
  Size: 2               Blocks: 8          IO Block: 32768  regular file
Device: 12h/18d Inode: 119276480   Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 4417/ (myname))   Gid: (  500/   users)
Access: 2010-09-27 19:14:02.785057213 -0400
Modify: 2010-09-27 19:47:27.622168948 -0400
Change: 2010-09-27 19:47:27.622168948 -0400

Name: Anonymous 2010-09-27 20:11

>>7
does that help you at all?

Name: Anonymous 2010-09-27 20:21

>>8
No, but I figured maybe you wanted to verify that I wasn't lying about file permissions or something.

It looks like I can stat the file.
struct stat hello;
if (stat("/home/donleyj/server/.wc", hello) < 0)
{
        error("could not stat");
}

Didn't return an error.

Name: Anonymous 2010-09-27 20:34

well i dont know then

Name: Anonymous 2010-09-27 20:55

What do you expect from a dead 40-year-old language? Try a more enterprise solution.

Name: Anonymous 2010-09-27 21:07

You need an n-tier end to end file opening solution. I suggest using WCF to implement a file open listener service which you can distribute across a WAN for increased redundancy, scalability, and return on investment.

Name: Anonymous 2010-09-28 3:25

>>1,9
[code] tags and mailto:sage, you flaming cretin.

Name: Anonymous 2010-09-28 6:53

Why would you help a person who puts "noko" into his sage field.

Name: Anonymous 2010-09-28 7:08

>>14
To annoy pieces of shit like you, I suppose.

Name: Goatse 2010-09-28 11:51

OPEN MY ANUS

Name: Anonymous 2010-12-17 1:27

Xarn is a bad boyfriend

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List