The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 find a specific value in a file

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
geovel Posted - 05/03/2005 : 05:53:03 AM
Origin Version (Select Help-->About Origin):7.0SR1
Operating System:Windows 2000

Hi guys,

I am trying to learn origin C for the last couple of weeks and I encountered some problems. I need to import a file into a worksheet (I am using the stdiofile command - as you know the importASCII command is not available in version 7). The files that I am importing have a few lines as comment on top and then the actual data follow. I wanted to ask if there is a way of finding a specific word in the file so as to import the data and not the comments. The problem is that the comments as well as the data do not have a fixed length (one file may include 60 lines of comments and 100 lines of data and the next one 105 lines of comments and 65 lines of data). Nevertheless in all files the data begin after a line with the header VD. Of course I will use some of the comments (around 5 lines) which are randomly located inside the comment lines.

Thank you in advance

George
4   L A T E S T    R E P L I E S    (Newest First)
Leo_Li Posted - 05/09/2005 : 05:17:32 AM
Hi George, Try the following codes. It is based on Francis's version.

void test()
{
string cfilename = "C:\\test.txt"; // Change to your file name here
string cLine(120);
string strLine(120);
FILE *ftemp;
ftemp = fopen(cfilename, "r");
if (ftemp != NULL)
{
fgets( cLine,120,ftemp );
strLine=cLine;
// Look for the beginning of the DATA block
while (!strLine.Match("*VD*") && !feof(ftemp))
{
fgets( cLine,120,ftemp );
strLine=cLine;
}
// start to read data...
}
}
geovel Posted - 05/09/2005 : 03:32:43 AM
Hi Francis,

I tried the code you send me but I can not compile it. Although I am not an expert in programming the code you send me looks like C. How do I compile a C code to Origin C? For exapmle the origin C compiler can not umderstand the command FILE. I look inside the stdiofile.h and file.h but I couldn't find anything.

George
geovel Posted - 05/03/2005 : 11:05:36 AM
Thank you Francis. I will try it and I'll let everyone know

George
ftalbot Posted - 05/03/2005 : 10:46:17 AM
Hi George,
Your can try something like:

"...
FILE *ftemp;
ftemp = fopen(cfilename, "r");
if (ftemp != NULL)
{
fgets( cLine,120,ftemp );
strLine=cLine;
// Look for the beginning of the DATA block
while (!strLine.Match("*VD*") && !feof(ftemp))
{
fgets( cLine,120,ftemp );
strLine=cLine;
};
...
};"

After that section, the next reading command will get the data.

If you also want to extract other information from your header (x-axis steps, column name etc...), try sscanf(). You might have to combine it with other pattern-matching loops like the one above, if all the lines in the header do not have the same formatting.
Hope it helps,

Francis.

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000