LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

file operation

Solved!
Go to solution

i need a program for accepting file through fileselectpopup and converting the file data(.txt) into .bin format and storing it into new file in same location. anyone please help out.

0 Kudos
Message 1 of 15
(3,171 Views)

Please don't double or triple your posts, people are not blind...

Also try to be more patient and give more details.

For example, did you try one of the samples shipping with CVI, see, e.g. listed here. They show how to use FileSelectPopup. Another starting point is this forum, e.g. the discussion here

 

 

Message 2 of 15
(3,150 Views)

sorry sir I am new to this forum so I posted wrongly.

 

void CVICALLBACK save_file (int menuBar, int menuItem, void *callbackData,
int panel)
{
int f1;
char File_path[500];
GetDir(File_path);
f1 = FileSelectPopup ("", "*.txt*", ".txt;", "df table", VAL_LOAD_BUTTON, 0, 0, 1, 0,File_path);

}

this is the code i wrote and i gave this callback funtion name to one of the menu panel,but when i run the program and select that option fileselect popup doesnt occur sir, i dont know whats wrong, i need program for accepting text file through file select popup and coverting it to binary and store it in new fle at same location. please help me out sir.

0 Kudos
Message 3 of 15
(3,131 Views)

the code you have shown is just fine - so your problem is somewhere else...

 

Just a recommendation: get used to initialize your variables, i.e.

int f1 = 0;

char File_path [ 500 ] = "";

is safer.

Message 4 of 15
(3,122 Views)
sir, fileselectpopup is coming now, i had made some mistake earlier so it was not coming. now i need help for getting the file from path name and converting it into binary format sir. this is my code now, void CVICALLBACK save_file (int menuBar, int menuItem, void *callbackData, int panel) { char **pathname; int i=0; i = FileSelectPopup ("", "*.txt*", ".txt;", "df table", VAL_LOAD_BUTTON, 0, 0, 1, 0, pathname); } please help me to access file and convert it into binary format.
0 Kudos
Message 5 of 15
(3,116 Views)

good, congratulations, the first step is done Smiley Happy

Now what you need to do is

- open the file for reading

- read it, line by line

- close the file

Since it looks that you are not too much experienced in C programming I would suggest that you try these three steps first, and once successful, we can add the code for writing the data as binary file.

Basically these steps can be implemented in two different ways, using either the ANSI C library with the functions fopen, fread, fclose..., or the functions provided by NIs Formatting and I/O Library, e.g. OpenFile, ReadLine, ScanFile, etc....

Message 6 of 15
(3,103 Views)

I tried to open file by creating a file name and by fopen instruction. Please can u write the program for reading the file data and converting to binary file and saving in a new file. I don't know c programming so I'm finding difficult please can u write that code and help?

0 Kudos
Message 7 of 15
(3,089 Views)

So what exactly did you try and what exactly did not work?

 

What is the purpose of asking questions here - surely not to have your homework done by others but to learn something new, no? Smiley Wink

 

So the code to read the first line of a text file is given below, but you have to work on it yourself: you first need to look up the commands (there is a help available in CVI...) and then you will need to add a loop for reading more than one line.

 

#include <formatio.h>
#include <userint.h>

static int file = 0;

static char buffer [ 1024 ] = ""; // depends on what kind of file you expect, i.e., what is the maximum number of characters per line
static char File_path [ MAX_PATHNAME_LEN ] = "";

if ( FileSelectPopup ("", "*.txt*", ".txt;", "df table", VAL_LOAD_BUTTON, 0, 0, 1, 0,File_path) > 0 )
{
    file = OpenFile ( File_path, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII );
    ReadLine ( file, buffer, 1023 );
    CloseFile ( file );
}

Message 8 of 15
(3,076 Views)

Hi, I want to read line without spaces. I've completed the code but I'm having trouble in reading line without spaces. I need buffer without spaces.

0 Kudos
Message 9 of 15
(2,923 Views)

Welcome back!

I am not sure I correctly understand your question - ReadLine does not care if the text consists of 'a's, '2's or spaces - it reads the input from file until it encounters a linefeed. Put differently, you can use ReadLine to read lines without spaces.

I only guess, but maybe your goal is to remove the spaces from the input buffer? Then, with the help of Google, you could find code such as this

Hope it helps Smiley Happy

Message 10 of 15
(2,920 Views)