|
Good idea, but still does not answer the original questio. SOrry.
|
|
|
|
|
It needs to write string to the file.
But it Open file return FALSE, GetLastError() = 3.
m_File2Write.Open(webRes.strLocalFile, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite))
{
DWORD error = GetLastError();
return -1L;
}
The file does not exists, but I think it will create a file. I do not know why Open file falied.
-----------------------------
Now I know why. Because there is the chararcter '-' in the file name. Such as 12-444.html
But if use the explorer to create file 12-444.html, it is ok. Why use CFile, it error?
modified 16-May-12 9:03am.
|
|
|
|
|
WinError.h :
OK the file does not exist and you want to create it, but what about its folder?
Veni, vidi, vici.
|
|
|
|
|
I know 3 means can not find the path, but I donot know why.
|
|
|
|
|
I would check with the debugger the runtime value of webRes.strLocalFile .
Veni, vidi, vici.
|
|
|
|
|
yu-jian wrote: It needs to write string to the file.
Having some Gollum flashbacks, are we?
Seriously, though, what is the value of strLocalFile ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
d:\temp\C030FA87-73C4-4989-99A2-CAABEB1F1FE2.html
|
|
|
|
|
You are trying to create a file and a path. Not possible with Open() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
In the above code you do not test the return value from Open , so the return value of GetLastError() does not mean anything.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
The full code is as follows:
if (!m_File2Write.Open(webRes.strLocalFile, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite))
{
DWORD error = GetLastError();
return -1L;
}
Just Open return FALSE, it will call GetLastError(), error is the err code.
|
|
|
|
|
Perhaps CFile doesnot support file name with character "-".
|
|
|
|
|
|
Of course it does, Windows would never work if that was the case. Can you show the exact string you are passing to the Open() call, as it exists in your code?
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Certainly,
strLocalFile is a CString type;
strLocalFile = _T("d:\temp\1FC69DCC-3B54-4DE4-8AEB-7094D0B23E01.html");
if (!m_File2Write.Open(webRes.strLocalFile, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite))
{
DWORD error = GetLastError(); // where error is 3
return -1L;
}
|
|
|
|
|
Try:
strLocalFile = _T("d:\\temp\\1FC69DCC-3B54-4DE4-8AEB-7094D0B23E01.html");
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
As the other Richard points out you have not escaped your backslash characters in the string, so the actual string being sent to the Open() function contains invalid characters. The "\t" part of the string is replaced by a tab character by the compiler.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Sorry,
The active value of variable strLocalFile is "d:\temp\1FC69DCC-3B54-4DE4-8AEB-7094D0B23E01.html".
I forgot to transmit it to c++ code. In c++ code, '\' should be '\\'.
|
|
|
|
|
That's not completely true.
Veni, vidi, vici.
|
|
|
|
|
You're right - again!
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Hello,
How to define horizontal profile
For EX; i have a vertical bar on an image of thickness - 40 Width & Height 400 . the possibility of getting defects also possible in bar. so i want to create a horizontal profile of length 0 to 40 ( by taking the uniformity and average pixels from the all 400 length)
so the horizontal profile is going to my reference profile - to verify the defects later .
i don know whether you guys under stand my question..but post me if you didnt
How to create a horizontal profile ??
|
|
|
|
|
Gday,
There's a page at Wikipedia on Fixed Pattern Noise, see here[^].
I think you are (probably) interested in calculating the DSNU.
If this is the case, I believe it involves the following steps.
1. Initialize totalLuminosity to 0.0
2. Create an array of numToProcess (400) elements - lumArray
3. Get pixel value
4. Convert colour(RGB) to HSL (Hus Saturation Luminosity)
5. Add the Luminosity value to totalLuminosity
6. Set lumArray[curPixelNum] to Luminosity
7. If #pixels processed < numToProcess(400) goto #3
8. Divide totalLuminosity by numToProcess(400) - this is your avgLuminosity
9. Create a second array with numToProcess (400) elements - diffArray
10. For each element in array from step 2, set difArray[i] = avgLuminosity - lumArray[i]
This will give you an array that tells you the difference between the brightness of each pixel and the average brightness of all pixels in the line.
Cheers,
S.
|
|
|
|
|
#include<stdio.h>
#include<string.h>
struct student
{
char name[20];
long int phone;
};
int main(void)
{
FILE *fp=fopen("student.txt","w+");
struct student s;
strcpy("dilip",s.name);
s.phone=123456789;
if(fwrite(&s,sizeof(struct student),1,fp)!=1)
printf("error");
fclose(fp);
return 4;
}
//BELOW IS THE UNREADABLE CONTENT WRITTEN TO FILE
//W$§#Â6W$1"ôSß"ÿÿ¢xÐ¥Q
-- modified 15-May-12 11:52am.
|
|
|
|
|
It would help if you put <pre> tags round your code so it looks like:
strcpy("dilip",s.name);
s.phone=123456789;
if(fwrite(&s,sizeof(struct student),1,fp)!=1)
In the above you have a strcpy() call with the source and destination reversed so your copy will fail (possibly silently). You also have a long int in your structure which is not a text value. So combining these two issues your file contains some bytes that do not show as clear text.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
dilipkumarc wrote: strcpy("dilip",s.name);
You have the source and destination reversed.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
consider opening the file for binary writing, because you want to write a struct with an int.
FILE *fp=fopen("student.txt","wb+");
Also, as the others mentioned before, it has to be:
strcpy(s.name, "dilip");
Also think about that:
const int NAME_LEN = 20;
struct student
{
char name[NAME_LEN];
long int phone;
};
char myLongName [] = "this_is_a_very_long_name_largerthan_20_chars";
strncpy(s.name, myLongName, NAME_LEN);
s.name[NAME_LEN - 1] = '\0';
Later on, I guess, you will copy a variable to the string. In the described way, you can be sure, not to overwrite the end of the char array. With only strcpy this could happen.
|
|
|
|