Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    c
  » Basic File IO in C
      by Christopher Hill -TrajectoryLabs.com
 Page 7 of 7 
< Previous    

(Login to remove green text ads)
Append text to a file using fputs()
Code:
// Append text to a file using fputs()

#include <stdio.h>
int main()
{
	char text[50];
	FILE *file_ptr; // 1. declare a FILE pointer
	file_ptr = fopen("lines.txt", "a"); // 2. open file

	if( file_ptr != NULL ) // 3. test
	{
		printf("File opened.\nEnter text to append: ");
		gets(text);
		fputs(text, file_ptr); // 4. write text
		fclose(file_ptr); // 5. close the file
		return 0;
	}
	else{ printf("Unable to open file.\n"); return 1; }
}





 
 Page 7 of 7 
< Previous    

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting