LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-21-2002, 12:41 AM   #1
kato678
LQ Newbie
 
Registered: Feb 2002
Location: New Hampshire
Distribution: redhat 7.2
Posts: 24

Rep: Reputation: 15
C prog..except input ,write to textfile??


Hi. Really new to Linux and a wee bit familiar with C. I want to write a small code that will ask user his/her name when run and then write it to a text file called name.txt . that's it.
thnks.
brian


i know the C code part but I dont know how I would write to a text file on the disk. I mean I know the printf, scanf parts, etc



thnks again.
 
Old 02-21-2002, 01:09 AM   #2
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
scanf() will handle the input. To write to a file on disk, you must open a file and use fprintf()

char *nm = "Malicious";
FILE *nf;

/* open a file in the current working
directory named "names.txt" */
nf = fopen("names.txt", "w");
/* write a name to it */
fprintf(nf, "%s\n", nm);
/* close it */
fclose(nf);

Let me know when you need some more homework done. :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a simple c prog to call a script RajRed Programming 1 10-05-2005 05:10 PM
how to write a simple c prog to call a script RajRed Linux - Software 1 10-05-2005 02:57 PM
Howto write XF86 Input Module? ZX_SA Programming 0 05-11-2005 09:11 AM
read the input file and write in the given format suchi_s Programming 8 12-17-2004 01:12 AM
Im trying to write a script or prog (newbie needs help desperatly!) bripage Programming 19 08-10-2002 09:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration