Is that for Class/Object function prototype, I must define the
function in header file or .cpp file.

MyClass::functionA();
MyClass::functionB();

but for C function prototype, I don't have to define if it's put
before the main() function the following is not needed -

void stradd (char *s1, char *s2);
void stradd (char *s1, int i);

=========
#include <iostream> // cannot be iostream.h??
#include <stdio.h>
#include <string.h>


#include <comdef.h>
#include <conio.h>
#include <windows.h> // must need for SYSTEMTIME

//must need C/C++ > General > Debug Information Format to debug
working

using namespace std; // for cout must have??

// concatenate two strings
void stradd (char *s1, char *s2)
{
strcat (s1, s2); // CRT <string.h> function
}

// concatenate a string with a "stringized" integer
void stradd (char *s1, int i)
{
char temp[80];

sprintf (temp, "%d", i);
strcat (s1, temp);
}



int main()
{
//SYSTEMTIME st = {0,0,0,0,0,0,0,0}; // cannot divide into 2
lines - must init all in one line
SYSTEMTIME st = {0}; // OK too

char str[80];
//char* str; // not OK will crash program

strcpy (str, "Hello ");
stradd (str, "there");
cout << str << "\n";

stradd (str, 100);
cout << str << "\n";

stradd (str, "hihi");
cout << str << "\n";

return 0;
}

Re: C function prototype by PvdG42

PvdG42
Sat Apr 12 17:57:06 CDT 2008

"June Lee" <iiuu66@yahoo.com> wrote in message
news:iue204d960od868lfjsmggru2b80vkctc3@4ax.com...
> Is that for Class/Object function prototype, I must define the
> function in header file or .cpp file.
>
> MyClass::functionA();
> MyClass::functionB();
>
> but for C function prototype, I don't have to define if it's put
> before the main() function the following is not needed -
>
> void stradd (char *s1, char *s2);
> void stradd (char *s1, int i);
>
> =========
> #include <iostream> // cannot be iostream.h??
> #include <stdio.h>
> #include <string.h>
>
>
> #include <comdef.h>
> #include <conio.h>
> #include <windows.h> // must need for SYSTEMTIME
>
> //must need C/C++ > General > Debug Information Format to debug
> working
>
> using namespace std; // for cout must have??
>
> // concatenate two strings
> void stradd (char *s1, char *s2)
> {
> strcat (s1, s2); // CRT <string.h> function
> }
>
> // concatenate a string with a "stringized" integer
> void stradd (char *s1, int i)
> {
> char temp[80];
>
> sprintf (temp, "%d", i);
> strcat (s1, temp);
> }
>
>
>
> int main()
> {
> //SYSTEMTIME st = {0,0,0,0,0,0,0,0}; // cannot divide into 2
> lines - must init all in one line
> SYSTEMTIME st = {0}; // OK too
>
> char str[80];
> //char* str; // not OK will crash program
>
> strcpy (str, "Hello ");
> stradd (str, "there");
> cout << str << "\n";
>
> stradd (str, 100);
> cout << str << "\n";
>
> stradd (str, "hihi");
> cout << str << "\n";
>
> return 0;
> }
>
>

In your simple example, you get away with providing full function
definitions before the compiler encounters the first call. The point of
prototypes is to give the compiler enough to recognize calls before the full
definition is parsed. In a more complex example, where you have numerous
functions which call each other, it can become impossible to define the
functions in an order that satisfies all calls. Prototypes obviate such
issues by ensuring the compiler will recognize all calls regardless of the
order of the full definitions.


Re: C function prototype by Vincent

Vincent
Sat Apr 12 19:00:54 CDT 2008

On Sat, 12 Apr 2008 15:47:37 -0700, June Lee <iiuu66@yahoo.com> wrote:

>// concatenate a string with a "stringized" integer
>void stradd (char *s1, int i)
>{
> char temp[80];
>
> sprintf (temp, "%d", i);
> strcat (s1, temp);
>}

Perhaps (?)

void stradd ( char *s1, int i )
{
_itoa( i, s1 + strlen(s1), 10 );
}

> //SYSTEMTIME st = {0,0,0,0,0,0,0,0}; // cannot divide into 2
>lines - must init all in one line

Quite acceptable (though pointless):

SYSTEMTIME st =
{
0
,
0, 0, 0,
0, 0, 0,
0
};
--
- Vince