If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > how to write the info to text file--> C language

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-05, 11:08
kennethlam kennethlam is offline
Registered User
 
Join Date: Jan 2004
Location: kuala lumpur
Posts: 18
Talking how to write the info to text file--> C language

I'm a university first year student, i have some question about the C programing language. My question show below

1)Write a C program to read an integer and a floating point number from the console and write them to a text file called "exercise3.txt"

my solution is

#include<stdio.h>

void main()
{
int i;
float f;
FILE *ofp;

printf("Please enter an integer number\n");
scanf("%d", &i);
printf("Please enter a floating point number\n");
scanf("%f", &f);

ofp = fopen("exercise3.txt", "w");
fprintf(ofp, "%d \n %f", i, f);

}

the exercise.txt file will automatic create, but the value i and f didn't write to the file.... how to solve this

Thank you
Reply With Quote
  #2 (permalink)  
Old 10-11-05, 23:27
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
I'd bet you need fclose() to flush the buffer and close the file.

-PatP
Reply With Quote
  #3 (permalink)  
Old 11-22-10, 16:48
94snecra01 94snecra01 is offline
Registered User
 
Join Date: Nov 2010
Posts: 1
Help

What is the syntax for "fclose()"? Is it the same as fopen()? If so what is the syntax for inside the brackets?
Will appreciate the help.
Reply With Quote
  #4 (permalink)  
Old 11-22-10, 17:18
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #5 (permalink)  
Old 10-10-11, 01:34
yuresh yuresh is offline
Registered User
 
Join Date: Oct 2011
Posts: 1
using of Fclose()

using of fclose() function is easy.
fclose(Fp);
where fp is the File pointer.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On