Hi,
I am very new to C++ (i.e. only begun using it in the last few weeks) and am currently maintaining an existing .dll file for the company i work for. After reading quite a few threads in this forum i see that the main sticking point for many newbies appears to be pointers, and i am no exception. I want to really grasp the concept of pointers and could use a really good explanation (if you know of any particularly good websites, please feel free to post a link).
Now, my current question concerns a call to a function, passing a character array..... -
...
-
...
-
...
-
char buffer1[10], buffer2[10];
-
-
GetDlgItemText(hWnd, IDC_C_LOW, buffer1, 10);
-
GetDlgItemText(hWnd, IDC_C_UP, buffer2, 10);
-
-
if( !checkFloatInput(buffer1) || !checkFloatInput(buffer2) )
-
{
-
EndDialog(hWnd, TRUE); // destroy the convexity dialog box
-
convexMin = 0;
-
convexMax = 0; // reset values
-
-
// simulated left-click
-
Convex_LtClick(NULL, NULL, NULL, NULL, NULL, hWnd, NULL);
-
break;
-
}
-
...
-
...
-
...
-
And the code for the checkFloatInput function is below: -
BOOL checkFloatInput(char aCharArray[]) //used to error-trap non-float data entered by the user
-
{
-
-
int tempAsciiValue;
-
bool result = true;
-
int numOfDecimalPts = 0; //
-
char errorMsg[60] = "Invalid input:\n\n";
-
-
for( int i = 0; i < int(strlen(aCharArray)); i++ )
-
{
-
tempAsciiValue = int(aCharArray[i]); // ascii value for character being considered
-
-
if( tempAsciiValue==46 || ( tempAsciiValue > 47 && tempAsciiValue < 58) )
-
{
-
if( tempAsciiValue==46 && numOfDecimalPts > 0 )
-
{
-
i = strlen(aCharArray); // force end of for-loop
-
strcat(errorMsg, " - Cannot have more than one decimal point.\n\nPlease re-enter.");
-
MessageBox(NULL,(LPCSTR)errorMsg, NULL, MB_OK);
-
result = false;
-
}
-
else if( tempAsciiValue==46 && numOfDecimalPts == 0 )
-
{
-
numOfDecimalPts++; //
-
aCharArray++; // move to next character in the array
-
}
-
else
-
aCharArray++; // move to next character in the array
-
}
-
else
-
{
-
i = strlen(aCharArray); // force end of for-loop
-
strcat(errorMsg, " - Non-numeric characters entered.\n\nPlease re-enter.");
-
MessageBox(NULL,(LPCSTR)errorMsg, NULL, MB_OK);
-
result = false;
-
}
-
-
}// end of for-loop
-
-
return result;
-
-
} // end of checkFloatInput function
-
The error message i get when compiling is as below:- error C3861: 'checkFloatInput': identifier not found
error C3861: 'checkFloatInput': identifier not found
error C2365: 'checkFloatInput' : redefinition; previous definition was 'formerly unknown identifier'
The problem appears to be the parameter i am passing in the if-statement. I have tried many permutations of how the parameter is passed and how it is received in the function, but frustratingly, i am always getting compile errors. I am sure the answer is very simple and it is just my lack of experience with pointers that is the problem - I am hastily reading up on the subject, but i am also trying to learn Matlab and OriginPro at the same time, and any help would be much appreciated.
Thanks,
Phil
2 1603 http://msdn2.microsoft.com/en-us/lib...yx(vs.71).aspx
Tip: Google can come in especially handy. So will MSDN when using Visual C++ and using WinAPI calls.
Diagnosis: Problem isn't the code within your function. The function itself is being called incorrectly. You have to pass in precisely the right number of parameters, and the correct type for each argument to the function when it is called.
Tip: Google can come in especially handy. So will MSDN when using Visual C++ and using WinAPI calls.
Diagnosis: Problem isn't the code within your function. The function itself is being called incorrectly. You have to pass in precisely the right number of parameters, and the correct type for each argument to the function when it is called.
Hi, thanks for getting back to me. I had already checked MSDN and had seen the page you recommended, but it still isn't quite 'clicking' in my mind yet. From MSDN, i understand that the GetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount) function takes the user's input and puts the string into a buffer pointed to by lpString.
I did some more reading (a pretty good intro to pointers in C can be found here for any other newbie's out there) around this area and amended my calling code as below:- -
char* buffer1 = "";
-
char* buffer2 = "";
-
-
UINT sizeBuffer1 = GetDlgItemText(hWnd, IDC_C_LOW, buffer1, 10);
-
UINT sizeBuffer2 = GetDlgItemText(hWnd, IDC_C_UP, buffer2, 10);
-
-
// Note, that buffer1 and buffer2 are pointers to buffers where text is stored.
-
-
if( !checkFloatInput(buffer1, sizeBuffer1) || !checkFloatInput(buffer2, sizeBuffer2) )
-
{
-
EndDialog(hWnd, TRUE); // destroy the convexity dialog box
-
....
-
....
-
....
-
I also amended my function a little, as below:- -
BOOL checkFloatInput(char * aCharArray, UINT sizeOfArray) //used to error-trap non-float data entered by the user
-
{
-
-
int tempAsciiValue;
-
bool result = true;
-
int numOfDecimalPts = 0; //
-
char errorMsg[60] = "Invalid input:\n\n";
-
-
for( int i = 0; i < (int)sizeOfArray; i++ )
-
{
-
tempAsciiValue = int(aCharArray); // ascii value for character being considered
-
-
if( tempAsciiValue==46 || ( tempAsciiValue > 47 && tempAsciiValue < 58) )
-
{
-
if( tempAsciiValue==46 && numOfDecimalPts > 0 )
-
{
-
i = (int)sizeOfArray; // force end of for-loop
-
strcat(errorMsg, " - Cannot have more than one decimal point.\n\nPlease re-enter.");
-
MessageBox(NULL,(LPCSTR)errorMsg, NULL, MB_OK);
-
result = false;
-
}
-
else if( tempAsciiValue==46 && numOfDecimalPts == 0 )
-
{
-
numOfDecimalPts++; //
-
aCharArray++; // move to next character in the array
-
}
-
else
-
aCharArray++; // move to next character in the array
-
}
-
else
-
{
-
i = (int)sizeOfArray; // force end of for-loop
-
strcat(errorMsg, " - Non-numeric characters entered.\n\nPlease re-enter.");
-
MessageBox(NULL,(LPCSTR)errorMsg, NULL, MB_OK);
-
result = false;
-
}
-
-
}// end of for-loop
-
-
return result;
-
-
} // end of checkFloatInput function
-
-
However, i am still getting the same compilation error message. My thinking at present is that, when i call checkFloatInput(buffer1, sizeBuffer1), buffer1 is a pointer to a char array and as the checkFloatInput() function is set up to take a char pointer as one of it's arguments, this should work - I have tried passing buffer1 as &(*buffer1[0]) also, as well as quite a few other variations but always get the same error, "error C3861: 'checkFloatInput': identifier not found". I have googled the issue of 'error C3861', 'passing char arrays' and variations on that theme but as i say, unfortunately something hasn't gone eureka in my mind yet and still need some advice if there is anything else you could recommend. I am sure that the problem is with an assumption i am making about pointer types that i haven't yet corrected.
Cheers for any further light you may be able to shed.
Phil
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hilary Zhang |
last post by:
Hi,
I have a headache with my program, which is a real-time graphic program
written in VC++ 6.0. I often get an error of "access violation" when run in
release mode. But if I use debug mode, it...
|
by: Gonçalo Rodrigues |
last post by:
Hi all,
I'm working around with smart pointers mostly as a learning exercise:
I have a single-rooted hierarchy with the root class Object. Every
Object has a member field count, the number of...
|
by: FKothe |
last post by:
Hello together,
the program below shows a behavior i do not understand. When compiled
with the HX-UX11 c-comiler ( version B.11.11.04 ) v2.p in function
test_it0 points to an invalid adress and...
|
by: Sathyaish |
last post by:
I am expecting a VBA code module in one of the VBA apps, but much to my
astonishment, I don't seem to find my way through it. It seems like I
am looking at a fully compiled binary.
I have an MDB...
|
by: Brian |
last post by:
Dear Programmers,
I have a class with a pointer to an array. In the destructor, I just
freed this pointer. A problem happens if I define a reference to a
vector of this kind of class. The...
|
by: Lame Duck |
last post by:
Hi Group!
I have a vector<floatvariable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front(), but when I get back a...
|
by: David Mathog |
last post by:
I have a program for which this line:
if(! lstrtol(&atoken,length-2,(long *) &(lclparams->pad)) ||
(lclparams->pad< 0)){
generates the warning below, but ONLY if the gcc compiler is at -O2 or...
|
by: WaterWalk |
last post by:
Hello. I thought I understood member function pointers, but in fact I
don't. Consider the following example:
class Base
{
public:
virtual ~Base() {}
};
class Derived : public Base
{
|
by: Brian |
last post by:
Hello -
I have been told that for extra efficiency we should always compile
code with frame pointer ommited (-fomit-frame-pointer), also -pipe.
What is the reason for this? Why does it make a...
|
by: simonl |
last post by:
Hi,
I've been given the job of sorting out a crash in our product for
which we have the crash information and an avi of the event (which
can't possibly match but more of that later...) (btw this...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |