C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 10th, 2003, 01:36 PM
buck1 buck1 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: great britain
Posts: 1 buck1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation dont know what is the error

hello,
ive made a program like a directry or archive but it wont compile
i dont know what it is becoase the compiler doesnt tell me why
here is the source code:

#include <stdio.h>

void list();

void about();

void open();

void menu();

void list()

int main()


{
char text[10];
FILE *file_ptr; /*declare a File pointer.*/
file_ptr = fopen("moretext.txt","r"); /*open the file.*/

if(file_ptr !=NULL)
{
printf("list of files:\n");
while(1)
{
next = fgetc( file_ptr );
if(next!=EOF)printf("%c",next);
else break;
}
fclose(file_ptr); /*close the file*/
return 0;
}
else { printf("unable to open the list.\n");
return 0;}
}


void menu()
{
int num;

printf("\n\tHello, please enter a number on what you want to do:\n\n");
printf("\t1. Show list of files\n");
printf("\t2. Open a file\n");
printf("\t3. who made this\n");
scanf("%d",&num);
switch(num)
{
case 1 : list(); break;
case 2 : open(); break;
case 3 : about(); break;
}
}

void about()

int main();
{
printf("\nThis program was made by Danny Michael Buck.\n\nMade in 2003
go to: www.buck1.pwp.blueyonder.co.uk for my website\n\n or e-mail me
at: buck1@blueyonder.co.uk\n");
menu();
}


void open()

int main()
{
printf("enter the name file you want to open and press enter/n")
scanf("%s",&name);
char next;
FILE *file_ptr;
file_ptr = fopen("%s","r",name);
if(file_ptr !=NULL);
return 0;
}

Reply With Quote
  #2  
Old November 10th, 2003, 01:42 PM
Kris_A Kris_A is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Manchester, UK
Posts: 58 Kris_A User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 1 m 33 sec
Reputation Power: 9
1. "void list()" has no semi-colon next to it
2: "next" in int main() is undeclared
3: inside "void about()" you have a declaration for "int main();" which is both in the wrong place and unnecessary

after fixing these i was given countless numbers of errors to do with mis-matched curly brackets. you really need to sort out the code to make sure everything matches up correctly. What compiler are you using? it must be pretty hopeless if it doesn't report any of these errors...

edit: there are a lot more missing semicolons. make sure you add one after every command. also, make sure you declare your variables before you use them, and don't put "int main()" inside any of your functions! this is a function itself and must be seperate to the others. EG:
Code:
int myfunc1();  // declarations in case 
int myfunc2();  // these functions appear after their caller (main() in most cases)

int main() {
  // call other functions from here
  myfunc2();

  return 0;
}
int myfunc1() {
  return 50;
}
int myfunc2() {
  return myfunc1();
}

Last edited by Kris_A : November 10th, 2003 at 01:51 PM.

Reply With Quote
  #3  
Old November 11th, 2003, 01:29 AM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,810 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 436
Send a message via AIM to peenie Send a message via MSN to peenie
There are a lot of syntax problems with your code, so I'll just try to point out some general stuff, then you can ask again if you are still having trouble after you try to fix up your code:

All sentences in English must end in a period, otherwise people won't quite get what you are trying to say. Likewise, all C/C++ statements must end in semicolons, otherwise the compiler won't know what you are trying to do.

The purpose of declaring functions first with no body is to let the compiler know that those functions are indeed defined, although there definitions might be later on in the file or in an entirely different file. These are called "prototypes", or function "declarations", and take the general form of:
Code:
return_type function_name (parameter_list);

Note the semicolon. Example:
Code:
/* tell the compiler that we will be defining list() later,
   so it won't complain. */
void list (void);

Functions must be declared before they are used, or else the compiler will whine about it.

When you define a function (i.e. you write the actual code for the function rather than just declaring that the function exists), you use the following general form:
Code:
return_type function_name (parameter_list) {
  function_body;
}

Note the lack of a semicolon after (parameter_list). For example:
Code:
void list (void) {
  int n;
  // do stuff here.
  printf("I'm printing this.\n");
  n = 34;
  printf("n is %i\n", n);
}

All functions must be defined at some point. Otherwise, the linker will whine about it and you'll get "undefined reference" errors.

All variables used inside a function must be declared. If they aren't, then the compiler won't know what symbols represent variables, and what types of variables they represent. Simply doing:
Code:
void func (void) {

  n = 23.0;
  m = n;

}

Does not give the C/C++ compiler enough information to work with. Instead, you would have to do:
Code:
void func (void) {

  float n, m;

  n = 23.0;
  m = n;

}


You can't end a line in the middle of a quoted string. However, putting two quoted strings in a row, separated only by spaces or newlines, will cause the compiler to join them in to one bigger quoted string when it compiles your code. So, the following two lines are the same:
Code:
printf("This is a string.\n");
printf("This " "is " "a " "str" "ing.\n");

With that in mind, if you need to use more than one line to specify a long string, do this:
Code:
printf("This is part of "
       "a big string. "
       "This is the end of it.");

Note that that will *not* actually print newline characters at the end of each of your lines. It will just print the whole string on one line. You have to explicitly tell printf to print newlines by inserting the character \n into your string when appropriate.

Sorry, I typed that pretty quickly. Hope it's coherent, and that it helps.

J.C.

Reply With Quote
  #4  
Old November 11th, 2003, 04:51 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,405 clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level)clifford User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 9 h 41 m 54 sec
Reputation Power: 1719
Re: dont know what is the error

Quote:
Originally posted by buck1
hello,
...i dont know what it is becoase the compiler doesnt tell me why...


What compiler are you using? If the compiler fails, (which it will on that code), it will produce an error log. Either, you are getting errors but you do not understand them, or you are getting errors but you do not know where they appear.

When you've found it, post the error log and I'll explain it. It is better that you learn how to use your compiler and how to understand its error reporting, than we just fix this one piece of code for you and leave you stranded for the next time. - "Give a man a fish and you will feed him for a day. Teach a man to fish and you will feed him for a lifetime."

Clifford

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > dont know what is the error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap