Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-12-2006, 09:50 PM   #1 (permalink)
CrazyJo82
Registered User
 
Join Date: Mar 2006
Posts: 1
CrazyJo82 is on a distinguished road
undeclared?

Hi, I'm new... I gave up months back when I tried to do C but I'm giving a 2. nd go at it. However, I've ran into the same problem... I'm using Osborne McGraw-Hill...

Could some some tell me and then explain why it's an error? I'm using Dev-C++

Code:
#include "stdio.h"

main()
{
      func2()
      printf("3 ");
}

func2()
{
       func1()
       pfintf("2 ");
}

func1()
{
       printf("1 ");
}
- 'func2' undeclared (first use this function)
-`;' before "printf"
- ISO C++ forbids declaration of `func2' with no type
and so on...

Code:
#include "stdio.h"

main()
{
      one();
      two();
}

one()
{
     printf("The summer solider, ");
}

two()
{
     printf("the sunshine patriot.");
}
this one is one the exercise but the same "undeclared" comes up as well... I checked the answer and that's the answer.

It's so fustrating that I copied exactly what the book said and it's still an error

Thanks for any help.
CrazyJo82 is offline   Reply With Quote
Old 03-12-2006, 10:01 PM   #2 (permalink)
Spook
Registered User
 
Join Date: Mar 2004
Posts: 9
Spook is on a distinguished road
Send a message via ICQ to Spook Send a message via AIM to Spook Send a message via Yahoo to Spook
Firstly, you should have return types specified for your functions. one() and two() ought to be void, and main should return an int - usually "0" or EXIT_SUCCESS.

Second, one() and two() need function prototypes so that the compiler knows that they're there. They look like...

return-type function-name(type, type);

As you'll notice, very similar to the top of a function itself, it just lacks a code block. In the specific case of one() it would look like...

void one(void);

Try making those fixes, ought to compile without a peep.
Spook is offline   Reply With Quote
Old 03-12-2006, 10:01 PM   #3 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 735
DJMaze is on a distinguished road
PHP Code:
#include "stdio.h"

void one();
void two();

int main()
{
      
one();
      
two();
}

void one()
{
     
printf("The summer solider, ");
}

void two()
{
     
printf("the sunshine patriot.");

A function must be declared before you use it
DJMaze is offline   Reply With Quote
Old 03-13-2006, 09:23 AM   #4 (permalink)
kyoryu
Registered User
 
Join Date: Apr 2003
Posts: 34
kyoryu is on a distinguished road
Alternately, if you have your main() function after one() and two(), it will also work... by the time main() is compiled, the compiler will have already seen one() and two(), and so it will work.

Code:
#include "stdio.h"

void one()
{
     printf("The summer solider, ");
}

void two()
{
     printf("the sunshine patriot.");
}

int main()
{
      one();
      two();
}
kyoryu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Organize Failure IbeNewb Standard C, C++ 9 04-14-2005 11:39 PM
Error C2065: Cstring undeclared identifier Layla Nahar Platform/API C++ 1 03-03-2005 08:27 AM
reading a folder of files Androto Standard C, C++ 29 12-21-2004 06:26 PM
My first post, I need help Zenogear11 Standard C, C++ 14 03-20-2003 12:01 PM


All times are GMT -8. The time now is 04:34 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting