file handling in capl programming - file-handling

please give me some hint how to perform File handling in CAPL programming.
How to open and how to access the file , what and which types of functions are available for file handling.
give some suggestion regarding this topics.
Thank you.

CAPL syntax provides you with some functions. To open a file stream for reading, use openFileRead();.
You may use function fileGetString() to read lines from such file. A code snippet might look like
char input[30] = "test.txt"
int bufferLength = 256;
char buffer[bufferLength];
dword fh;
fh = openFileRead(input,0);
while(fileGetString(buffer,bufferLength,fh)!=0) {
// do whatever
}
Please put some more effort next time: this is not how StackOverflow works.

Related

Reading characters within a file (the fseek command) not working in nxc (not-exactly-c) programming

Basically I'm trying to write code that reads a specified value from a file ex: file contains(12345) the code reads specific place (say the 3rd place) and the output = 3
I already know how to write numbers to a file but I am stuck on how to read a character because the fseek command won't work (it doesn't know what the command is). I downloaded the include folder with all the extra commands but it still couldn't find the file "stdio.h" in the code.
I don't completely know how it all works anyway
I am a complete noob in programing and so I only know the very basic stuff. I am 90% sure it is my fault it isn't working.
#include "cstdio.h." //gets error (doesn't recognize command/file)
task main ()
{
byte handle;
int fsize = 100;
int in;
int sus = 12345;
DeleteFile("int.txt");
CreateFile("int.txt",100,handle);
Write(handle, sus);
CloseFile(handle);
OpenFileRead("int.txt",fsize,handle);
fseek(handle, 10, 3); //gets error (doesn't recognize command)
in = fgetc(handle);
ClearScreen();
NumOut(30,LCD_LINE5,in);
Wait(100000);
CloseFile(handle);
}

C++ - read and write pcapng files without libpcap

I'm interested in reading and writing pcapng files without using libpcap or WinPcap. Anyone knows how to do it?
I can recommend a C-library which does that, it's called LightPcapNg and apparently PcapPlusPlus is using it to have a cleaner C++ wrapper.
Since you're interested in C++, here is a code snippet of how to read a pcap-ng file using PcapPlusPlus:
#include <PcapFileDevice.h>
void readAndWritePcapNg(char* inputFileName, char* outputFileName)
{
// reader instance
PcapNgFileReaderDevice readerDev(inputFileName);
// writer instance
PcapNgFileWriterDevice writerDev(outputFileName);
// open reader and writer
readerDev.open();
writerDev.open();
RawPacket rawPacket;
// read packets from file
while (readerDev.getNextPacket(rawPacket))
{
Packet packet(&rawPacket);
// do whatever you want with the packet
....
....
// write the packet to the output file
writerDev.writePacket(rawPacket);
}
// close reader and writer
readerDev.close();
writerDev.close();
}

How to read and write a text file in ActionScript 2.0 (Macromedia Flash 8)

I'm making some Animation project with Macromedia Flash 8, which uses ActionScript 2.0. I need some simple options like to save user to text file and read it. But, I couldn't find about writing to text file. Found some code that reads, but not writes.
Example of reading:
loadText = new LoadVars();
loadText.onData = function(raw) {
myField.text = raw;
}
loadText.load("user.txt");
Can someone help me, with examples of writing, parsing read data. Shortly, Working External data.
I appreciate any help that you can provide.

Writing in binary files in Delphi

I'm making a program in delphi that writes data to a binary file and I have a problem I do not understand how to solve.
I have the following code:
testar: = TFileStream.Create ('test.exe', fmOpenWrite);
testar.Position: = testar.Size;
here: = '{test} test {test}';
testar.Write (here, 1024);
Tested with WinHex
http://img836.imageshack.us/img836/3206/la49.jpg
This edition fine prints in the binary code because when I see it with WinHex looks good, but this other code:
testar: = TFileStream.Create ('test.exe', fmOpenWrite);
testar.Position: = testar.Size;
here: = '{test}' + Edit1.Text + '{test}';
testar.Write (here, 1024);
It does not show anything at all because it seems that there is a problem with the edit when you want to edit the binary code, it's weird because when
I use it all goes single quotes but with the example of the edit does not work.
Note: The program does not give any error message
Someone could help me with this problem ?
You have provided non-real code, but I suspect that "here" is string.
To write string body to stream, you can use the next code:
test.Write(PChar(here)^, SizeOf(Char) * Length(here));
P.S. If you are going to read this string from stream (file) later, then it would be wise to write its length before string body.

Illegal text-relocation error, how to embed a text file?

I am currently developing an application in which the first step its to load a text file and read its contents.
For example:
string file = "myfile.txt";
i am calling another function in which i want to look for a certain pattern/occurrence
void read(string pattern, const char *content) {
char subString [blocksize];
int n;
char *search = pattern;
pos = strstr(content,search);
.....
The function works perfectly on my Mac, but once I try to compile the application the compiler throws some error ld : illegal text-relocation.
The text file is in the same folder as the target app.
I'm assuming this has something to do with embedding the text file?
hope someone can help or give a hint !
thanks in advance

Resources