|
is the string longer than 2 characters? if so, you're overrunning the "id" buffer.
also, try opening the file in "r" mode, , not "rb".
-c
When history comes, it always takes you by surprise.
|
|
|
|
|
the string is 3 characters("npf"), but i thought it was like this:
id[0]="n"
id[1]="p"
id[2]="f"
and since it is id[3] there should be enough room.. right?
so dont u mean longer than 3 characters?
and i also thought the fscanf function reads in the data dependant of the size of the variable that is passed, so that it cant overrun the buffer...
or is this incorrect? i'm just guessing though, it's what i'd presume since there arent any other parameters passed to fscanf() which indicate what length it is.
But anyways, that cant be the problem anyways because i can display the id fine in a messagebox, the error only shows when i use fclose() or maybe after that... i'm not sure, because this is code for a function in a class i am writing. This is what i do(the class is called CNPFfile):
int main(int argc, char *argv[])
{
CNPFfile npf("npffile.npf");
BOOL bv = npf.IsValidNpfFile();
return 1;
}
I also tried opening the file in "r" mode, that didnt help.
Thank you kindly
Kuniva
--------------------------------------------
|
|
|
|
|
a string will have a 0 byte at the end. to read a 3 character string, you need a four byte buffer.
-c
When history comes, it always takes you by surprise.
|
|
|
|
|
OO WAIT lol
if i make it id[1000] then it works without errors... hmm so i guess fscanf doesnt get the number of bytes to read from the variable passed, oops. Hmm strange..
But anyways, what i'm actually trying to do here is to read in a serialised file, but not entirely, just some sort of header with a constant length. Like for example these are the first 8 bytes and the matching ASCII thingies:
6E 70 66 00 05 00 00 00
n p f
so i would think fscanf would stop at the 00 no?? Geesh this is complicated, maybe there is another function i should use for this? (i don't want to use MFC) I tried fread() already but didnt know how to start reading from a certain position with that cause i thought it always just started at the beginning, or can i use fseek() for that as well??
Kuniva
--------------------------------------------
|
|
|
|
|
I have been using C for nearly 20 years now. scanf is still a total mystery to me.
Since you are just passing the address of the string to fscanf, it has no idea how much space it can write over. This is one of many problems iostreams tried to fix with print/scanf.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
ok nevermind, it appears i can use fread for the job, thanks anyways
Kuniva
--------------------------------------------
|
|
|
|
|
Did you add null character end of id?
change your code to this:
<br />
char id[4]=NULL;<br />
fscanf(npf, "%s", id);<br />
id[3]='\0';<br />
A. Riazi
|
|
|
|
|
Hello All,
I have been having a problem I just don't know how to get by. I have a common dialog set up that I configure as I need at run-time. The default properties in the rc is CHILD and no FRAME (which is the majority of the times I need it) I have tried to change it to a pop-up window using ModifyStyle as well as SetWindowLong with out any luck. Anyone have any suggestions as to how this can be accomplished?
|
|
|
|
|
I'm not sure if someone in here can help. For a school project my son needs to write a code module in C to find the multiplicative inverse of ( X mod(26) ) using C-code if X and 26 HAVE common prime factors.
I'm a VB person and can't help him at all. Anybody out there that could give some advice?
Thanks
Claus
|
|
|
|
|
Is the problem with the math or the code? If you post a vb function that does it, then it will be simple to port it to C.
|
|
|
|
|
I guess I wasn't clear enough. I have no clue how to go about this and was hoping for a code example that would help me to understand how to do this.
Claus
|
|
|
|
|
If Y is a multiplicative inverse of X mod(26) then (X*Y) mod(26) = 1. But the only factors of 26 are the primes 2 and 13, so if X and 26 have common prime factors then X = 26*Z. Then (X*Y) mod(26) = (Z*Y*26) mod(26) = 0 for any Y, so X has no multiplicative inverse mod 26.
This looks like it might be helpful.
http://math.uh.edu/~minru/web/lincong2.html
|
|
|
|
|
This was exactly what I was hoping for. The site link is great too. Thanks, I'll relay that to my son.
Claus
|
|
|
|
|
Hello!
I want to eject and close cd rom drive. I implemented code through calls to DeviceIoControl function. But I cannot find out, how to detect that drive is ejected or closed
thanks in advance
|
|
|
|
|
I am a student preparing a final year project. My project involves a Microsoft C DLL (no class functions) to be called by VB program running under Win 98. I need to develop a progress bar in C DLL but not VB. The CProgressBar in www.codeproject.com is nice but I do not know how to incorporate it into my existing program.
In fact, I have tried to insert a new class name "CProgressBar" with base class "CProgressCtrl" as public but unsuccessful. The following reject message is displayed:
"The New Class Wizard could not find the appropriate header file to include for the base class CProgressCntrl. If you choose to derive from the class anyway, you may need to manually add the appropriate header file to C:\Mydata\ProgressBar.h."
I shall be most grateful if anyone can kindly advise how to solve this problem and how to show an AVI file at the same time.
Thank you for your kind attention.
wavewave
|
|
|
|
|
First question:
Just copy the "afxcmn.h" - File to your project dir.
Second:
You can use vfw32 (VideoForWindows) to play an Avi file. It's very simple...
|
|
|
|
|
Dear AnTri,
Thanks for your kind reply. I have copied the file into my project dir but still experience the same problem. I have inspected the afxcmn.h which does define the CProgressCtrl class. I wonder if the problem is due to my project is selected as Win32 DLL.
Is there any sample program to call vfw32 to play AVI file?
What is the calling statement from a VB program that passes an array of fixed length string to C which will return string values through the array?
Thanks for your kind help.
wavewave
|
|
|
|
|
Hello WaveWave,
you can define your fixed string in vb(a) like
dim fixString as string(80)
Progressbar:
I think CProgressCtrl is an MFC-Class. You can't use MFC-clases in Win32-DLL project!
Avi:
please post your e-mail adress so I can mail you an example of an gnu-avi player, which you can use in your dll.
|
|
|
|
|
Hello WaveWave,
you can define your fixed string in vb(a) like
dim fixString as string(80)
Progressbar:
I think CProgressCtrl is an MFC-Class. You can't use MFC-clases in Win32-DLL project!
Avi:
please post your e-mail adress so I can mail you an example of an gnu-avi player, which you can use in your dll.
You habe to compile your dll using the stdcall-convention. The best way is to implement an .def file... (See MSDN)
|
|
|
|
|
Dear Antri,
Thanks for your prompt reply. My email is coolcool883@hotmail.com.
Is there any alternative if I have to provide progress information to user?
For parameter passing, if I have to pass an array of 10 elements each of which is a fixed length 80 byte string. How should I define in my VB and how can I update the array element in my C program?
Thanks for your kind help.
Regards,
wavewave
|
|
|
|
|
'to define the Usertype Array:
Public Type MyArray
String1 As String * 81 ' : array[1..81] of char; // 80 byte string
String2 As String * 11 ' : array[1..11] of char; // 10 byte string
end type
dim MyRecord as MyArray
'to define the dll-function in vba:
Declare Function MyCppDLL Lib "CppTest.dll" Alias "FirstFunctionName" (MyRecord As MyArray) As Byte
'in c++ define the same record with struct.... and you can access the strings (char String[n]) stored in the UserRecord (struct)
|
|
|
|
|
Thanks for your advice.
How can I define an array of 25 strings each of 255 bytes, i.e.
String[01] of 255 bytes
String[02] of 255 bytes
String[03] of 255 bytes
:
:
String[25] of 255 bytes
Thank you.
wavewave
|
|
|
|
|
How to use this API to get the info of remote machines? Here is my sample code.. I am getting a memory error . Can anyone suggest me where i went wrong. Is there any other way to pass the first argument(machine name) to the API?
////////////////////
//getting details of machines
wchar_t *tmp4=(wchar_t *)malloc(sizeof( wchar_t ));
strcat(mbstr2,tempname[snum]);
mbstr2[strlen(mbstr2)]='\0';
size_t x=strlen(mbstr2);
mbstowcs(tmp4,mbstr2,x);
WKSTA_INFO_101 *level=NULL;
LPTSTR tmp7=(LPTSTR)tmp4;
NET_API_STATUS nwData=NetWkstaGetInfo(tmp7,101,(LPBYTE*)&level);
if(nwData==NERR_Success)
{
int iLen3=wcslen ((unsigned short *)level->wki101_computername);
for(int j=0;j<ilen3;j++)
{
="" name[j]="*(level-">wki101_computername);
level->wki101_computername++;
level->wki101_computername++;
}
name[j]='\0';
AfxMessageBox(name);
//////////////////
Kindly help.
Regards,
Vini
|
|
|
|
|
I don't understand all that string manipulation at the beginning.
The first param is either NULL to use the local computer, or a Unicode string holding the name of the computer to get info for, for example L"\\Servername"
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
BUY MY SOFTWARE!! (please?) RightClick-Encrypt | 1ClickPicGrabber
My IntarWeb Homepgae!!!11
|
|
|
|
|
Michael Dunn wrote:
don't understand all that string manipulation at the beginning.
The first param is either NULL to use the local computer, or a Unicode string holding the name of the computer to get info for, for example L"\\Servername"
I want to give the first argument at run time(not a NULL value),means give the selected machine name from a list box or edit box. The initial string manipulations were used to convert the value in a CString variable to the type of the first parameter . is it not required? Kidly help..
Vini
|
|
|
|