Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text files creation and MS-DOS commands

Status
Not open for further replies.

AlexTardif

Programmer
Apr 11, 2002
14
CA
Hi,

I need some help about creating text files. I use Windows 98 and I want to create text files in different directories. These directories are "under" the program directory.

I was thinking doing this way :

#include <stdio.h>

#define N 300

void main(void)
{
FILE *fp;

/* that's where my question comes...
char fname[N] = &quot;/path1/path2/../pathN/fileXXXX.ext&quot;;
or
char fname[N] = &quot;\path1\path2\..\pathN\fileXXXX.ext&quot;;
or
char fname[N] = &quot;path1/path2/../pathN/fileXXXX.ext&quot;;
or
char fname[N] = &quot;path1\path2\..\pathN\fileXXXX.ext&quot;;
or
char fname[N] = what else??? */

fp = fopen(fname, &quot;w&quot;);

/* file writing ... and treatment */
}

By the way, all the paths are already created.

I tried the four declaration types and the files are never created, fopen() always return NULL.

I have some paths and some files that are longer than the xxxxxxxx.xxx format, does it matter in C? What do I do wrong?

I have another question (always in Windows) : Can I use MS-DOS commands in my C programs? And how can I call it? Example :

cd pathx in C : cd(&quot;pathx&quot;); ????
rmdir pathy in C : rmdir(&quot;pathy&quot;);

Thank you for all the answers!

Alex
 
you should use '\\' instead of '\' in your path because '\'followed by a character has a specially meaning. for example, '\n' means a carriage return.

you can use :
system(&quot;cd pathx&quot;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top