Currently doing C programming homework, I want to update the value in the file. But now I'm having a problem updating it. The problem I faced now was the codes below update the values but in the form of new lines. Instead of replace the original lines. What's wrong with my codes ? FILE* phoneFile; int position_in_file,newStock; printf("Enter new stock: "); scanf("%d",&newStock); position_in_file = ftell(phoneFile); fseek(phoneFile,position_in_file,SEEK_SET); fprintf(phoneFile,"%s %s %d %d %d\n",mobile[i].mCode,mobile[i].mName, &mobile[i].mCost,&mobile[i].mPrice,newStock);

Member Avatar
Member Avatar
+0 forum 2

I am trying to write a multiline string into a text file but it does not appear as multi-line text. Here's my code $hostname = "localhost"; $username = "root"; $password = "sample"; $dbname = "code"; $code = <<< THECODE ; This is the main configuration file for your web app ; The web administrator shall set the correct settings to initialise the app [dbconfig] hostname = $hostname username = $username password = $password databasename = $dbname THECODE; $fp = @fopen('config.ini','w') or die_message("Could not write configuration file</br>Change your folder permissions using <b>chmod 777</b>"); fwrite($fp, $code); fclose($fp); But when I open the …

Member Avatar
Member Avatar
+0 forum 1

so i have the following code and is not working // Make user folder if (!is_dir('../user/'.$name)) { $user_folder = mkdir('../user/'.$name, 0777); $user_index = copy('../login/user.php', '../user/'.$name.'/index.php'); if ($handle_append = fopen('../user'.$name.'index.php', 'w')) { echo 'Succes opening the file'; } else { echo 'Error opening the file'; die(); } $string = 'text to write'; if (fwrite($handle_append, $string)) { echo 'Succes writing the file'; } else { echo 'Error writing the file'; die(); } fclose($handle_append); $user_inf = copy('../login/user_inf.php', '../user/'.$name.'/user_inf.php'); } else { echo 'Acest nume de utilizator exist&#259; deja, te rug&#259;m alege alt nume!'; exit(); }

Member Avatar
Member Avatar
+0 forum 3

I want to add text string at the end of the text file. I used "a+" for it but it delete all the content and than enters text to it. So please help.

Member Avatar
Member Avatar
+0 forum 9

I am trying to create a code that will generate a webpage. Here is what I have so far. I am looking to just take data that is queried from our server and display it on a page. Their is a form that is populating the ID on the query and all the information is pulling correctly. It's just when it comes to creating the file and page contents it's getting lost. <?php $id1 = $_POST["id1"]; echo $id1; echo "<br>"; $id2 = $_POST["id2"]; echo $id2; echo "<br>"; $id3 = $_POST["id3"]; echo $id3; echo "<br>"; $name = $_POST["name"]; echo $name; echo …

Member Avatar
Member Avatar
+0 forum 3

Hello Everyone..!! I am beginner at PHP. I would like to have solution for "\n" in textfile php. $file = "testFile.txt"; $fh = fopen($file, 'a+') or die("can't open file"); $firstname = $_POST["prenom"]; $lastname = $_POST["nom"]; $mood = $_POST["humeur"]; $datestring = date("d/m/y "); $timestring = date("H.i.s"); $data = "$firstname ; $lastname ; $mood ; $datestring : $timestring "\n" "; fwrite($fh, $data); fclose($fh); Actual Result: testprenom ; testnom ; bonne ; 19/10/12 : 11.09.23 ; ; ; 19/10/12 : 11.09.25 Expected Result: testprenom ; testnom ; bonne ; 19/10/12 : 11.09.23 Thanks a lot for your time in advanced.

Member Avatar
Member Avatar
+0 forum 13

Im grabbing a page with below. $homepage = file_get_contents('http://www.example.com/'); echo $homepage; How do I write it to a file.txt and overwite in the event the file exists ? Thanks.

Member Avatar
Member Avatar
+0 forum 2

I have a project that, instead of using MySQL, I am supposed to use txt files to manage data. I have no say in this, I'm doing the project for a client. So I wrote a test file with functions for writing these data files, reading, etc. But it's not acting correctly. I call read the content of a file, let's say it has 1 line in it. I then call the function to write an entry to the file. I then read the contents of the same file again, but it still shows only the 1 entry. I then …

Member Avatar
Member Avatar
+0 forum 2

Hi, I'm currently working on a school project ..i was wondering if someone can help, i'm creating a system which get's data from a database and creates a CSV file ..i Google a lot none of it helps, i want to get several rows from a table and write it as a .DAT format(passes as text) i know it's not a standard file format, but my teacher insists.by the way, for example i have a table which contains: full name , last name , age , sex. i want to get full name, last name .. using [CODE]mysql_fetch_array[/CODE] method and …

Member Avatar
Member Avatar
+0 forum 3

Hey, I have a question on fwrite. I know that fwrite can write things to your server, for instance, but when I put try to write C:\foo.txt, will this actually save it to my server, or to the clients computer? If not, then is there any way that I can save it on the clients computer? Thank you, glut.

Member Avatar
Member Avatar
+0 forum 4

plz somebody help with this code . i m fed up now [CODE]<?php $x=5; echo $x; session_start(); $_SESSION['y']=$x; $string = '<?php session_start(); $x=$_SESSION['y']; echo $x;?> '; $fp = fopen("6.php", "w"); fwrite($fp, $string); fclose($fp); ?>[/CODE]

Member Avatar
Member Avatar
+0 forum 5

Everytime I run this program and enter a new record, it gets terminated on these statements: [CODE] stud.pcent=((stud.mhin+stud.meng+stud.mmat+stud.msci+stud.msst)*100)/(mm.hin+mm.eng+mm.sst+mm.sci+mm.mat); fwrite(&stud,recsize,1,file); [/CODE] The whole program is this. It is only partially complete. [CODE] #include<conio.h> #include<iostream.h> #include<stdlib.h> #include<string.h> #include<stdio.h> #define UARROW 72 #define DARROW 80 #define ENTER 13 #define ESCAPE 27 int key; char s=219; FILE *file,*tmp; long int recsize; void getkey(); struct profile { char fname[15],lname[15],month[10]; int date,year,grade,roll,admin; float meng,msst,mmat,msci,mhin,pcent; }stud; struct max { float hin,eng,sci,sst,mat; }mm; void addrec() { fseek(file,0,SEEK_END); int ctr=0; while(ctr==0) { gotoxy(5,2); cout<<"You are in the record entry module. Follow the steps to enter the record successfully."; gotoxy(10,4); …

Member Avatar
Member Avatar
+0 forum 3

I am trying to find out how to replicate the output of fwrite("andbe", 4, 1, output); an encryption algorithm I am using writes its output as this, but I am sending data across a network, and need to be able to write this to a string to send. The algorithm writes all of its output in 4-byte chunks, and reads them the same way. The problem is that it also writes strings that are much less than 16 characters as four bytes, which it can read with fread("...", 4, 1, input) but I cannot seem to replicate as just strings? …

Member Avatar
Member Avatar
+0 forum 1

hi all, I have a php script that saves what the user types in into a text file using fwrite, and displays it on another page using file_get_contents. When putting in a pound sign (£), it saves the following to the text file: £ Any idea how I can stop this from happening and instead get the pound sign working properly? Max.

Member Avatar
Member Avatar
+0 forum 3

The End.