Hi I am a little bit new to C's advanced topics:
I need help in file handling.
I have Turbo C and I wrote a simple program to write data to file:
#include<stdio.h>
#include<dir.h>
#include<conio.h>
#include<stdlib.h>
// program to write your name to a file
void main()
{ FILE *pt;
char *b;
chdir("d:\test");
pt=fopen("bharat.text","w");
printf("ENter ur name ");
scanf(" %[^\n]",b);
fprintf(pt," %s",b);
fclose(pt);
getch();
}
When I executed the program, a new file("bharat.text")was created in
the BIN directory under the Turbo C directory. I wish that the file
should be created in "D:\TEST" folder.
Can any one tell me how to do that? 4 4590
BHARAT wrote: Hi I am a little bit new to C's advanced topics: I need help in file handling. I have Turbo C and I wrote a simple program to write data to file:
#include<stdio.h>
#include<dir.h> #include<conio.h> #include<stdlib.h>
// program to write your name to a file void main() { FILE *pt; char *b; chdir("d:\test"); pt=fopen("bharat.text","w"); printf("ENter ur name "); scanf(" %[^\n]",b); fprintf(pt," %s",b); fclose(pt); getch(); }
When I executed the program, a new file("bharat.text")was created in the BIN directory under the Turbo C directory. I wish that the file should be created in "D:\TEST" folder. Can any one tell me how to do that?
Change "d:\test" to "d:\\test" or "d:/test".
Bjørn
"BHARAT" <mr***********@gmail.com> writes: Hi I am a little bit new to C's advanced topics: I need help in file handling. I have Turbo C and I wrote a simple program to write data to file:
#include<stdio.h>
#include<dir.h> #include<conio.h> #include<stdlib.h>
<dir.h> and <conio.h> are non-standard headers.
// program to write your name to a file void main()
Make that "int main(void)".
{ FILE *pt; char *b; chdir("d:\test");
The "\t" expands to a tab character. If you want a backslash
character in a string, you need to double it:
chdir("d:\\test");
pt=fopen("bharat.text","w"); printf("ENter ur name ");
Apart from the misspellings, stdout is typically line-buffered, so the
message may not appear before the scanf(). Add
fflush(stdout);
scanf(" %[^\n]",b); fprintf(pt," %s",b); fclose(pt); getch();
getch() is a non-standard function.
You should have a "return 0;" here.
}
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
In article <0d********************@telenor.com>,
=?ISO-8859-1?Q?Bj=F8rn_Augestad?= <bo*@metasystems.no> wrote:
(someone else) When I executed the program, a new file("bharat.text")was created in the BIN directory under the Turbo C directory. I wish that the file should be created in "D:\TEST" folder. Can any one tell me how to do that?
You'll get the usual:
Not portable. Can't discuss it here. Blah, blah, blah.
but see below anyway...
Change "d:\test" to "d:\\test" or "d:/test".
Or, more to the point, get in the habit of checking the return value of
system/library calls.
On 6 Dec 2005 23:38:10 -0800, "BHARAT" <mr***********@gmail.com> wrote
in comp.lang.c: Hi I am a little bit new to C's advanced topics: I need help in file handling. I have Turbo C and I wrote a simple program to write data to file:
#include<stdio.h>
#include<dir.h> #include<conio.h> #include<stdlib.h>
// program to write your name to a file void main() { FILE *pt; char *b; chdir("d:\test"); pt=fopen("bharat.text","w"); printf("ENter ur name "); scanf(" %[^\n]",b); fprintf(pt," %s",b); fclose(pt); getch(); }
When I executed the program, a new file("bharat.text")was created in the BIN directory under the Turbo C directory. I wish that the file should be created in "D:\TEST" folder. Can any one tell me how to do that?
In addition to everything Keith pointed out, you have a real problem.
You have defined a pointer to char, b, but have not created any
characters for it to point to, nor have you initialized it to point
anywhere.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hans-Joachim Widmaier |
last post by:
Hi all.
Handling files is an extremely frequent task in programming, so most
programming languages have an abstraction of the basic files offered by
the underlying operating system. This is...
|
by: Sean W. Quinn |
last post by:
Hey folks,
I have a question regarding file handling, and the preservation of class
structure. I have a class (and I will post snippets of code later in the
post) with both primitive data...
|
by: John Douglass |
last post by:
I'm fairly new to doing involved file i/o and I came across something
weird with a program I'm writing (modifying MIDI data, if it makes any
difference). With some input files, when I modify data...
|
by: Gabe Moothart |
last post by:
Hi,
I'm writing a windows service which interacts with a separate process.
Basically, it calls a process which creates a file, and then my service
reads that file. The problem is, the external...
|
by: Al Smith |
last post by:
I need help in implementing proper error handling.
I am trying to upload a file based on the sample code below. The code works
well except if the file selected is too big.
I do know about the...
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting"...
|
by: Digital Puer |
last post by:
I fixed a bug today that went against my intuition. I am on Linux.
I had a class that fopen'ed some files. When I called delete
on these objects, I expected that the files would be closed...
|
by: rmr531 |
last post by:
First of all I am very new to c++ so please bear with me. I am trying
to create a program that keeps an inventory of items. I am trying to
use a struct to store a product name, purchase price,...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming.
FYI
Although I have called...
|
by: kailashchandra |
last post by:
I am trying to upload a file in php,but it gives me error msg please Help me?
My Code is like below:-
i have one php file named upload.php and i have another html file named upload.html and...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |