|
I hate to say this, but I never cease to be amazed at the number of questions I manage to answer just by looking at the documentation.
|
|
|
|
|
I know.
When I originally looked at OnDraw, I did not want to use it because I expected to have to redraw everything (inner, outer, fill, text and theme support)
But it ended up to look something like:
OnDrawn(...)
{
if (condition)
pDC->FillRect(...);
else
pDC->FillRect(...);
__super::OnDraw(...)
}
I'd rather be phishing!
|
|
|
|
|
hi
i have grid view in asp.net project .and this grid view have different information in each page how can i use tool-tip in each cell
thanks
|
|
|
|
|
"i have grid view in asp.net"
Are you sure that are you on the right forum ? 
|
|
|
|
|
well after hours of work I finally managed to combine 2 scripts that i worked on
The purpse of the code is to get an adress of the folder that includes different kind of files
and the code needs to open the folder that is near it (2 folders in 1 folder)
and compair each time 2 files 1 is the compairer and the second is on of the files that is in the path in argv[1]
but every time after I combined the code and tried to fix it theres a triggered breakpoint
If anyone could tell me how to solve the problems in my script I will be very greatfull
the part where it doesnt work is at the while in the function at the end
here is my code:
http://pastebin.com/C5BYSNYK
modified 24-May-15 11:10am.
|
|
|
|
|
You still have lines of code of the form:
char* entrenceToTheFolderBefore = (char*)malloc(NULL);
which, as I explained will lead to problems: you will either get strange results, or a program crash. If you are going to store data in the buffer returned from malloc then you must allocate enough space for the data you are going to copy into it. Anything less will cause your program to overwite other variables.
|
|
|
|
|
i cant allocate because it gives me garbage every time i add 1
or simply try to allocate
can you rewrite it to make more sence ?
|
|
|
|
|
OK, let us say that you have a path ("C:\Users\Noname\Documents\Test") in argv[1], and you now want to inspect a subdirectory called "images":
int argvSize = strlen(argv[1]); int mallocSize = argvSize + strlen(subdir) + 1 + 1;
char* newPath = (char*)malloc(mallocSize);
strcpy(newPath, argv[1]); strcat(newPath, "\\"); strcat(newPath, subdir);
|
|
|
|
|
for some odd reason it still adds me junk letters that 1 last null
int temp3 = location + 1;
char* entrenceToTheFolderBefore = (char*)malloc(sizeof(char)*temp3);
for (int i = 0; i < location; i++)
{
entrenceToTheFolderBefore[i] = argv[1][i];
}
puts(entrenceToTheFolderBefore);
is there any way we could communicate like through skype ? i have only 2 hours left before the handout
|
|
|
|
|
Yes because you are using the count from location to do the copy, which is the length of the string, and so will not include the null character. Use the code sample I gave you which makes use of standard library functions that will ensure your copied data is correctly structured.
a random user wrote: is there any way we could communicate like through skype ? Sorry, I do this in my own time and at my own speed. I will not be available much longer today.
|
|
|
|
|
Ok then..
I did what you told me but the results are still the same
The problem is in the second while
and in entrenceToTheFolderBefore 1 more bit as null gives me =@$&!%
int temp3 = location + 1;
char* entrenceToTheFolderBefore = (char*)malloc(sizeof(char)*temp3);
for (int i = 0; i < location; i++)
{
entrenceToTheFolderBefore[i] = argv[1][i];
}
puts(entrenceToTheFolderBefore);
location2 = location;
while (location2 != argvSize)
{
location2++;
UnwantedName[countLoop] = argv[1][location2]; // problem
countLoop++;
}
OtherDir = opendir(entrenceToTheFolderBefore);
while (OtherEnt = readdir(OtherDir)) ////UnwatedName = C2_Mid_Anti-Virus_Project.zip
{
if ((strcmp(OtherEnt->d_name, UnwantedName) != 0) && (strcmp(OtherEnt->d_name, ".") != 0) && (strcmp(OtherEnt->d_name, "..") != 0)) //problem
{
strcpy(InfectedFolderPath, entrenceToTheFolderBefore);
strcat(InfectedFolderPath, "/");
strcat(InfectedFolderPath, OtherEnt->d_name);
puts(InfectedFolderPath);
}
}
closedir(OtherDir);
modified 24-May-15 13:30pm.
|
|
|
|
|
a random user wrote: I did what you told me but the results are still the same That's because you did not do what I told you. You are still copying your path strings based on strlen rather than strlen +1. And you seem to be creating too many variables, most of which are just duplicates of existing items. This may well be what is causing you confusion.
|
|
|
|
|
i did try that but the extra byte always when i do puts() adds alot of random letters
int temp4 = argvSize - location; //temp4 = 30
char* UnwantedName = (char*)malloc(sizeof(char)*temp4);
int temp3 = location+1; //temp3 = 24
char* entrenceToTheFolderBefore = (char*)malloc(sizeof(char)*temp3);
for (int i = 0; i < location; i++)
{
entrenceToTheFolderBefore[i] = argv[1][i];
}
puts(entrenceToTheFolderBefore); // ---> C:/Users/win7/Desktop/1=(alotof ascii characters
|
|
|
|
|
That is because you keep doing the same thing wrong. You need to stop and think, and reread all my posts that explain how to do it properly. Especially look closely at the sample code I posted yesterday
|
|
|
|
|
i did do waht you told me i expended the string by 1
but that 1 byte is messing up my code
even trying using strcat just makes it worse I stopped and read all of ur recent psots but i have nothign that comes in mind that could help me
im sorry for giving you a hard time here but it is hard for me as it is
would you please fix the code to show me what you mean?
|
|
|
|
|
|
I did calculate the bytes and the characters as i needed it needs to be 24 bytes
when at the last code i posted you can see that until i reach to the point that is /1 its 23 bytes
the + 1 is the one i added so it will be the end of the string
|
|
|
|
|
well.. im trying to open a folder with an unknown number of programs
using argv and argc through the cmd to the adress of the folder
i need to use the dirent.h and maybe the FILE struct
to open the files
the code needs to open each file and search the text within (it has mp3 signatures etc) in a binary way and search through it with a second file that the text inside of it is not in any place in there
in other words i need to spot if the second file's signature is nto repeatign anywhere on the other files
this is the far that i got but im stuck
can anyone help me?
#include <stdio.h>
#include <stdlib.h>
#include "dirent.h"
int main(int argc, char** argv){
int count = 0, size = 0;
int sizes[3];
FILE *log = fopen("C:\\Users\\win7\\Desktop\\1\\C2_Mid_Anti-Virus_Project.zip\\AntiVirusLog.txt", "wt");
DIR *dir;
struct dirent *ent;
int found = 0;
dir = opendir(argv[1]);
while ((ent = readdir(dir)))
{
count++;
sizes[0] = strlen(argv[1]);
sizes[1] = 2;
sizes[2] = strlen(ent->d_name);
size += sizes[0] + sizes[1] + sizes[2] + 1;
char* string = (char*)malloc(sizeof(char)*size);
_flushall();
strcpy(string,argv[1]);
strcat(string, "\\");
strcat(string, ent->d_name);
FILE* youtube = fopen (string, "rb");
if (youtube != NULL)
{
print("success \n");
}
puts(ent->d_name);
}
fclose(log);
closedir(dir);
return 0;
}
|
|
|
|
|
a random user wrote: this is the far that i got but im stuck So what exactly do you need help with? You need to explain clearly what part of your code does not work.
|
|
|
|
|
Looks to me like you're most of the way there. You probably want to read in your reference file into a buffer. You can use _stat() to get the file size for malloc().
Next, it depends on where the signatures are in the file. If they're at a known location you could use fseek(), fread() and memcmp() to determine if the signature is in the file or not. If the signatures are at a random location, I'd pull the entire file into a malloced buffer (_stat() again), and then search through the buffer. The simple way would be use memcmp() at locations 0 ... (current_file_size - reference_file_size), but there's more efficent ways of going about that. If you know that there's no null chars in the either file (unlikely), maybe strstr() is an option.
some notes on what you have so far:
sizes[0], and sizes[1] will not change over the while loop, so they could be computed before entering the loop.
strlen("\\") is 1, not 2
you not calling free(string) within the while loop, so you're leaking memory. If you use my suggestion about slurping the file into memory, don't forget to free() that buffer too.
|
|
|
|
|
Ok i somehow managed out to open the files BUT all I have left now is to search inside these files for the signature
modified 23-May-15 7:36am.
|
|
|
|
|
First you need to write down the steps you require to do the searching. Something like:
Read 'key' file and extract its signature
For each file in directory
Do
Open next file
Read some data (maybe a small amount, maybe all, or maybe just some specific block)
If the key-file signature is in the data of this file
Then
Do file match processing
Else
Do file no match processing (if necessary)
EndIf
Until (no more files)
Once you have all the steps clearly defined it should not be too difficult to turn that into code.
|
|
|
|
|
thank you but atm im trying to figure out how to open the folder that contains the folder that I entered in argv
because its a fodler inside a folder that contains files
as you can see it doesnt work
int count = 0, size = 0, totalDirs = 0,location = 0;
int sizes[3],flag = 0;
int secSpot = 0;
int argvSize, spot = 0;
char c;
argvSize = strlen(argv[1]);
for (int i = 0; i < argvSize; i++)
{
if (argv[1][i] == '/')
{
spot++;
}
}
for (int i = 0; i < argvSize; i++)
{
if (argv[1][i] == '/')
{
if (secSpot != spot)
{
secSpot++;
}
else if ((secSpot == spot) && (flag == 0))
{
location = i;
flag++;
}
}
}
location--;
char* entrenceToTheFolderBefore = (char*)malloc(sizeof(char)*location);
for (int i = 0; i < location; i++)
{
entrenceToTheFolderBefore[i] = argv[1][i];
}
puts(entrenceToTheFolderBefore);
free(entrenceToTheFolderBefore);
modified 23-May-15 9:06am.
|
|
|
|
|
A folder in a folder is just a new path to search. When you get a directory in your dirent search, you just append a backslash '\\' followed by the directory name to the string you got from argv (or the current path), and start a new search. Say you start your program by:
program C:\Users\Random\Lists
and your found entry is a directory named Music, you would create a new path C:\Users\Random\Lists\Music and continue with that. Don't forget to ignore directories named . and .. as they lead back up the tree.
|
|
|
|
|
insteadof entering "\\" my teacher told me that I could use / to make it quicker
my problem is tho that when I do puts i get garbage and not the output i wanted as a link outside of the argv folder
|
|
|
|