08-12-2010 02:12 AM
I am having a string control in the uir. This is entered by the user. ( something like a path).
How can I get this user entered path and use it as a path to save a file? i have done something like this...is this correct??
The control has the constant name STRING_2. I try to get the value from that control and assign it to a value pt_s.
Can any1 help?
double *pt_s; pt_s = &s; GetCtrlVal ( panelHandle, PANEL_STRING_2, pt_s ); int w; FILE *OutFile = fopen("pt_p","w"); fprintf(OutFile,"This is a test to open,write and save something to a sig file"); fclose(OutFile);
Solved! Go to Solution.
08-12-2010 03:13 AM
You need to reserve some actual space in your program for the string contents. Something along the lines:
char string [512];
GetCtrlVal (panelHandle, PANEL_STRING_2, string);
You can then pass this variable directly to fopen().
It seems from your code that you have some fundamental misunderstandings about programming in C - have you considered taking a course?
JR
08-12-2010 06:54 AM
char string [512]; GetCtrlVal (panelHandle, PANEL_STRING_2, string); int w; FILE *OutFile = fopen("string.txt","w"); fprintf(OutFile,"This is a test to open,write and save something to a sig file"); fclose(OutFile);
When i give the string obtained in the fopen(), it saves the file with name string.txt.I dont need that. I need to save the file as given in the user entered control.. For Example i give the input path as C:\\Users\\Student\\Desktop\\Tes33t.txt. The path, file name and format is already in this input. I just need to save the data enetred in to this file.
08-12-2010 07:10 AM - edited 08-12-2010 07:12 AM
Use
FILE *OutFile = fopen(string, "w");
The name of the file is the first argument to the function, when you use
FILE *OutFile = fopen("string.txt","w");
you are telling fopen() to create a file named string.txt
There is also no reason for the line
int w;
in your code. The "w" in the argument to fopen() is also a string.
You might want to find a C tutorial.
08-12-2010 07:47 AM
ufff.. nw evrything getting complicted.
NON-FATAL RUN-TIME ERROR: "StimulsSignalTestV3.c", line 195, col 9, thread id 0x00001E8C: Library function error (return value == -4 [0xfffffffc]). Panel, pop-up, or menu bar handle is invalid
NON-FATAL RUN-TIME ERROR: "StimulsSignalTestV3.c", line 199, col 25, thread id 0x00001E8C: Library function error (return value == 0 [0x0]). (ENOENT) No such file or directory
FATAL RUN-TIME ERROR: "StimulsSignalTestV3.c", line 201, col 17, thread id 0x00001E8C: Null pointer argument to library function.
08-12-2010 07:47 AM
ufff.. nw evrything getting complicted.
NON-FATAL RUN-TIME ERROR: "StimulsSignalTestV3.c", line 195, col 9, thread id 0x00001E8C: Library function error (return value == -4 [0xfffffffc]). Panel, pop-up, or menu bar handle is invalid
NON-FATAL RUN-TIME ERROR: "StimulsSignalTestV3.c", line 199, col 25, thread id 0x00001E8C: Library function error (return value == 0 [0x0]). (ENOENT) No such file or directory
FATAL RUN-TIME ERROR: "StimulsSignalTestV3.c", line 201, col 17, thread id 0x00001E8C: Null pointer argument to library function.
08-12-2010 08:02 AM
Can you write your line 195 to 201 to see your problem. The first is maybe your panel handle which is not the same in your panel properties and in your fonction...
08-12-2010 08:14 AM
thnx Simon
The panel handle was not the same as in panel properties and in my function. That was the problem. Now it worked. Thanks...
08-16-2010 08:23 AM
I have aniothe rproblem in the same situation.
I obtain a file path in the main.c progrm.
GetCtrlVal (panelHandle, PANEL_STRING_2,string1);
I defined this string1 outside the main like this:
char string1 [512];
and i created another common.h file which included :
extern char string1 [512];
so that i can call string1 in another function.
Now i need its value(string1) in another test.c file. I tried like this :
FILE *OutFile = fopen(string1,"w");
But i got this error. why is this:
error:
NON-FATAL RUN-TIME ERROR: "generate.c", line 14, col 21, thread id 0x00000718: Library function error (return value == 0 [0x0]). (EINVAL) Invalid argument
thanks
08-16-2010 09:31 AM
What was the actual contents of string1 at the point the error occurred? The CVI debugger should be able to tell you - break into your program and hover the mouse over the variable name. It is likely to be an illegal OS path/filename.
JR