| | |
Read and write in the same file
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
Hello guys,
How can I read and write in the same file? I want to open a file that exists and write something in the end of each line of the file..
Ex:
My_file:
a b c
d e f
g h i
I want to alter to:
a b c XX
d e f XX
g h i XX
I tried this but the file does not altered..
I tried a lot of thing like open in other modes, and nothing
thanks
How can I read and write in the same file? I want to open a file that exists and write something in the end of each line of the file..
Ex:
My_file:
a b c
d e f
g h i
I want to alter to:
a b c XX
d e f XX
g h i XX
I tried this but the file does not altered..
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> int main() { FILE *f; f = fopen("file.txt", "a+"); while (fgets(line,sizeof(line),f)){ fputc("XX",f); } fclose(f); return 0; }
thanks
Last edited by Ancient Dragon; Nov 27th, 2008 at 10:05 pm. Reason: add code tags
![]() |
Similar Threads
- Image read and write operations in turbo C (C)
- Read/write to same file > once, Help (C++)
- Random access read write (Visual Basic 4 / 5 / 6)
- Question about file read/write (Java)
- XP SP2 installation error: "unable to read from or write to the database" (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: How to draw a graphical window in c?
- Next Thread: Troubleshooting a simple function
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework inches include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






