PDA

View Full Version : alittle code help



gamehunter101
November 12th, 2006, 00:19
well i was following this tut and did it the exact same way but its not compiling




#include <iostream>

using namespace std;

void printString(void);

void simpleFunc (void);

void main()

{
cout <<"Before Function Call"<<endl;

printString();

cout <<"After Function Call"<<endl;

}

void simpleFunc (void);

{
cout <<"We are inside simple func"<<endl;
}

void printString(void)

{
cout <<"In Function Call"<<endl;

cout<<"Hello World"<<endl;

simpleFunc();
}





error
c:\documents and settings\pc\desktop\p2vid\functions2\functions2\fu n2.cpp(14) : errorC2447: '{' : missing function header (old-style formal list?)



thanks for the help

yaustar
November 12th, 2006, 00:27
Change:

void simpleFunc (void);
{
cout <<"We are inside simple func"<<endl;
}

to

void simpleFunc (void)
{
cout <<"We are inside simple func"<<endl;
}

gamehunter101
November 12th, 2006, 00:30
Change:

void simpleFunc (void);
{
cout <<"We are inside simple func"<<endl;
}

to

void simpleFunc (void)
{
cout <<"We are inside simple func"<<endl;
}

Thanks so much just would like to know what is the difference between the 2 of them

gamehunter101
November 12th, 2006, 01:25
i have the same problem with this one here


#include <iostream>
using namespace std;

void printString(char *str);
int stringlength(char *str);

void main()
{


int strlen = stringlength ("Dan");
cout<< strlen<<endl;
}

int stringlength(char *str);

{
int length =0;
while (str[length] != '/0')/*!=doesnt= to know character 0*/
lenght++;/*movin to next char in string*/

return length;
}


void printString(char *str)
{

cout<<"Hello"<< str <<endl;
}

DeNitro
November 12th, 2006, 03:39
You need to remove the ; at the end of

int stringlength(char *str);

so it becomes

int stringlength(char *str)

(Not from the top declaration part, but from the actual function in the middle if your code)

--DeNitro

yaustar
November 12th, 2006, 15:26
void simpleFunc (void); is a function declaration.
void simpleFunc (void) is the start of a function definition.