PDA

View Full Version : Creating files using plain C project in Qt Creator (command FILE)



Kapsu
10th October 2014, 07:10
Hi! Newbie here.

I was working on a C project before using Ubuntu, but now I have switched to Windows7 and want to continue my work. I got Qt Creator and was thinking that this would solve all my problems... All I would have to do is start a "plain C project" and copy whatever I had previously. Everything else is going great, except for one thing: the program cannot create data files. Does this mean that the old "FILE" command from C doesn't work in Qt Creator? Or is this possibly some sort of problem with permissions to access files that Qt has?

I read from other threads that there is some sort of "Qt FILE" command to create files, but I want to make sure whether I would be able to use FILE command from C language to create files or not. I could not find an answer with the search button, so I might have been using the wrong keywords..

Also, here is the part of my code that handles the file-making. If there is some way to make it work, I'd like to hear it. :)



void save_file(np,xp,yp,up,vp,rax,ray,tp,dp,mp,fname,ti me,fn)
int np,time,fn;
double *xp,*yp,*up,*vp,*rax,*ray,*tp,*dp;
int *mp;
char fname[];
{
FILE *fp;
int i,k;
char fname_full[200];

sprintf(fname_full,"%s_nor.%05d",fname,fn);
fp=fopen(fname_full,"wt");
if(fp==NULL) {printf("\n Cannot create file1 %s \n",fname_full);exit(1);}

fprintf(fp,"%d\n",np);
for(k=0;k<np;k++)
fprintf(fp,"%lf %lf %7.6e %7.6e %lf %lf %d\n",xp[k],yp[k],up[k],vp[k],tp[k],dp[k],mp[k]);

if(fclose(fp)==EOF)
{printf("\n Error in closing file %s \n",fname_full);exit(1);}

}

wysota
10th October 2014, 07:17
Qt Creator is a text editor, it has no influence on how your program behaves thus it cannot prevent you from using any language functionality in your program, especially at runtime. If you cannot create a file then most likely you don't have write permissions on the directory you are trying to create the file in.

Kapsu
10th October 2014, 12:35
Thank you for the fast answer.

How do I change the write permissions of the files to which I want Qt Creator to have access to (In Windows 7)?

anda_skoa
10th October 2014, 13:44
You misunderstood: this is not about QtCreator at all. It is just an IDE, it creates the executable of your program but is not involved in its execution.

You'll need to check that your program has access to whatever resources it needs from the operating system, e.g. files.
Ask on a Windows forum if you are uncertain how it manages access rights.

Cheers,
_

Kapsu
10th October 2014, 16:10
Understood, thank you for the quick reply