Jump to content

Issues with fgets()


proggR

Recommended Posts

So I'm reading in the first line of a file to compare it with the data I want to add to it and if they match it should return a message saying that the data is already there. But It doesn't seem to happen. It just jumps to my else option and prints the data into the file anyway. So I had it printing my fgets value and aparently its not seeing the /n and its grabbing two pieces of data from the file (which take up the first line when you look in notepad) and so of course that value and my one new piece of data don't match.

Is there any reason for this? I'm on a Windoze machine so would I have to use fopen($file, 'a+t');?

I could just go through and add ."/r/n" "\r\n" instead of ."/n" "\n" to the fwrite since I'm still just testing everything and haven't actually used it on a larger scale yet but I'm writing this on a Windows laptop and will later be uploading it to a Linux server and would rather not write it this way. But is it safe to say that's what's happening here?

 

 

Pee Ess. I've been reading around and I think the general concensus is no, but is there any way to append to the beginning of the file? Like r+ except it doesn't overwrite the data? I'll probably have to read the old data and then rewrite it but I'd rather not if I could avoid it. Thanks.

 

 

 

*edit* made the noob mistake of using the wrong slashes in my OP. Sorry

Link to comment
Share on other sites

If your really are using /r/n and /n then they mean nothing. They ought be \r\n and \n

 

I'll probably have to read the old data and then rewrite it but I'd rather not if I could avoid it.

 

It cannot be avoided.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.