|
This may seem like a silly question, but let's say we've got a pointer to a character array labeled str.
What is the difference between calling:
free(*str);
free(str);
Wouldn't free(*str) just free whatever single character the pointer is currently pointing to? This seems pointless? But it's called like this all over the place in this piece of code I've just been given to fix so I'm trying to figure out why they put it in.
The problem is that the call to free(*str) is sometimes crashing the code, even when it's checked like so:
if (*str)
free(*str);
Thanks!
|
|
|
|
|
>>Wouldn't free(*str) just free whatever single
No. This type of logic is usually used for multi dimensional arrays.
str should be a pointer to a pointer, and derferencing it makes you point to the first element of a two dimensional array.
So str points to the pointer of pointer array, and (*str) points to the array of objects.
Check the following code:
http://code.axter.com/allocate2darray.h
http://code.axter.com/allocate2darray.c
Make sure that your code is setting the pointer to NULL after calling free. You may be free data that has already been freed.
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
If I need to retrieve a URL, preferable asynchronously, which is a better API to use:
URLDownloadToFile
or
WinInet InternetXXX functions?
I am writing a high level wrapper around this stuff and I'm not sure which is the best API to use.
From looking at some articles here on CP it seems there are various issues with WinInet, while URLDownloadToFile seems MUCH easier to use, and it's easy to handle authentication for password protected resources.
My only concern is that it seems that URLDownloadToFile depends on IE being present. Is this worth being concerned about?
Thoughts?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Pfft, I guess it helps to look closer
It would appear that URLDownloadToFile is in urlmon.dll, not IE. Don't know why I thought that.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
URLDownloadToFile has been introduced with Internet Explorer 3.0, so I don't think the problem is practical. If you want to be perfect, you may check for the IE version during installation and perform the update if needed - however I haven't seen a 9x system with IE 2.0 or lower for ages! I personally use much preferred Mozilla Firefox, but the IE libraries are always in the system anyway.
Regards,
BB
http://spin.bartoszbien.com
|
|
|
|
|
OK.
Other than the IE dependency, is there any reason NOT to use URLDownloadToFile? It just seems so easy to use, I can't fathom why anyone would fight with the WinInet functions?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Hi all,
There's some code I "inherited" a few years ago and never really had much of an opportunity to clean it up in a significant fashion until now. I've always left all the little nagging things in there because of time constraints.
One thing that's been bugging me for a long time is that for every registry I/O operation occuring in this code (hundreds, some in loops), the original developer first verified the OS the program was running on. If it's Win9x, the string built to open a registry key is formatted to start with HKLM\SOFTWARE. If it's something from the NT line, then the string is HKLM\Software.
Is this absolutely, positively pointless? Are there any circumstances under which, if I settle on one case (without doing the check) the registry I/O call will fail? I've NEVER come across anything that would indicate this could happen, but at the same time I've never come across anything that guaranteed it would always work either regardless of case. My own tests on everything from the original Windows 95 all the way to Vista 5219 show that this check is utterly useless, and I could skip it entirely.
I'm very tempted to do so (and thus get rid of hundreds of these calls, and streamline all the registry string building code in the program), but not before I can find some (Microsoft?) documentation reassuring me that case sensitivity in registry key names is irrelevant.
Anyone can give me a convincing argument to leave this seemingly useless code in there? I mean, surely this check was added in the first place for a reason...?
|
|
|
|
|
|
Hi there,
I found a way to put any control or form I want into the taskbar (not just the Icon).
I'm not covering elements in the taskbar, I modify the size of the tasklist in the taskbar to prepare it to add a control afterwards. This works fine but I need to know when something has been changed in the taskbar. This means I need to know if an icon is added into the taskbar, if the taskbar gets hided, if the position is changed, etc...
Does anybody know if there exists breadcast messages which are sent by the taskbar?
Thanks in advance!
-- modified at 14:59 Tuesday 4th October, 2005
|
|
|
|
|
Great f*cking googly moogly.
Somehow my dialog editor in VC7 broke; I no longer have access to the tools that add controls to a dialog!!!! The itms for adding controls are visible, but they are disabled at all times, even when a dialog is being edited.
I'm using VS.NET 2002.
Anyone know how to fix this pathetic state of affairs?
|
|
|
|
|
Fixed it. Restarting VS.NET did not help; rebooting the system did.
Whatever.
|
|
|
|
|
Hi all,
Iam looking for the C++ code for the following Question asap? if anybody can do it please reply back soon and also let me know how soon they can do and how much it costs. thank u..........
Introduction
Reverend Zeller developed a formula for computing the day of the week on which a given date fell or will fall. Suppose that we let a, b, c and d be integers defined as follows:
a = the number of the month of the year, with March = 1, April = 2, and so on, with
January and February being counted as month 11 and 12 of the preceding year
b = the day of the month
c = the year of the century
d = century
For example, July 31, 1929 gives a = 5, b = 31, c = 29, d = 19; January 3, 1988 gives a = 11, b = 3, c = 87, d = 19. Now calculate the following integer quantities:
w = the integer quotient (13a – 1)/5
x = the integer quotient c/4
y = the integer quotient d/4
z = w + x + y + b + c – 2d
r = z reduced modulo 7; that is, r is the remainder of z divided by 7; r = 0 represents
Sunday; r = 1 represents Monday, and so on.
Specific Instructions
Implement a MyDate class to represent a date. The input has to be read as a string using an overloaded input operator. Preferably, no accessor function should be used to set the values of the data members. While reading the specified date, your program should validate the format i.e. while July 31, 1929 would be correct, 7/31/29, July 31, 29, 31/7/29 for example would be incorrect. The MyDate object should be able to find its own day of the week! Write a test program that illustrates the use of your MyDate class. The input to test the program should include the following:
July 31, 1929
January 3, 1988
March 21, 05
December 12, 1960
9/31/2005
July 4, 1776
January 1, 1991
Include all the source code (well documented) and input files and sufficient representative output.
sreek
|
|
|
|
|
Do your own homework, you worthless parasite.
|
|
|
|
|
repati wrote:
if anybody can do it please reply back soon and also let me know how soon they can do and how much it costs.
yup, can do. $1000 US per hour, 10 hours minimum payable in advance. respond in private and i will let you know where to send the cheque or money order. i will start coding when the money is in my account.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Well... yes that certainly is cheaper than I would have quoted...
If a wizard fails to cast an enchantment correctly, is that a mis-spelling?
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
hi for all
This is a simple question but I have no idea how I can do this:
How can I read all lines from a file and insert a new line in a specific local?
thanks a lot for all
Alex Cutovoi
|
|
|
|
|
|
Alex Cutovoi wrote:
How can I read all lines from a file...
For MFC, look for CStdioFile::ReadString() . Otherwise, you can use STL, fopen() /gets() , CreateFile() /ReadFile() . Take your pick.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
This is my code:
FILE *pFile;
MessageBox(0, thefile, "Erro", 0);
pFile = fopen(thefile, "r");
if(pFile != NULL)
{
while(!EOF)
{
fgets(linha, 100, pFile);
printf("%s", linha);
}
}
else
{
MessageBox(0,"File cound not be opened", "Error", 0);
}
fclose(pFile);
I think that my code is correct but the file doesn't open, what's wrong?
|
|
|
|
|
Alex Cutovoi wrote:
pFile = fopen(thefile, "r");
If thefile does not specify an absolute path, fopen() will only work if the file is in the same folder as the program itself.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
this is the part where I call my function
int main()
{
AbrirArquivo("c:\file.txt");
return 0;
}
the error persists, what's going on?
|
|
|
|
|
You need to use two backslahes. As it stands, fopen() tried to open a file named c:ile.txt .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
My new code is this:
#include <windows.h>
#include <stdio.h>
int iNotas[7];
void AbrirArquivo(const char* theFile)
{
FILE *pFile;
char linha[100];
pFile = fopen(theFile, "r");
if(pFile != NULL)
{
while(!feof(pFile))
{
fgets(linha, strlen(linha), pFile);
printf("%s", linha);
}
fclose(pFile);
}
else
{
MessageBox(0,"file not found", "Error", 0);
}
}
int main()
{
AbrirArquivo("c:\\file.txt");
return 0;
}
Thanks for help.
The problem remains there, #@$%%%@@#!
|
|
|
|
|
Alex Cutovoi wrote:
fgets(linha, strlen(linha), pFile);
This should be:
fgets(linha, sizeof(linha), pFile);
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi all
Article "A light-weighted client/server socket class in C++" explains how to make a client/server application, but i am a beginner and want to know if there are tutorials out there that are simple to use and that explains, step by step, how to create the server application and the client application.
The apps should use sockets and be as simple as possible (basically just be able to wait for a request (server) and then send an acknowledgement to the client (just a basic text message). it should really only illustrate the basic phases: 1) idle(server waiting for a connection), (2)connection establishment, (3)data transfer, (4)termination.
I know that you need the ip address as well as well as a port for communication - but that is basically all i know
if there is anyone who can help by writing a basic program (or tutorial), or even refering me to websites (one for beginners, as all the websites i find are a bit advanced and confusing for the novice C++ network programmer), I would most certainly appreciate it.
thank you.
|
|
|
|
|