473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

c structure errors

im a student of c and cant get why this program keeps bringin me errors
thanks for the help
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main()
  3. {
  4.     struct database[20];
  5.     {
  6. char namec[6];
  7. int work_h;
  8.     };
  9. }
Mar 5 '07 #1
14 2260
r035198x
13,262 8TB
im a student of c and cant get why this program keeps bringin me errors
thanks for the help
#include<stdio.h>
main()
{
struct database[20];
{
char namec[6];
int work_h;
};
}
Where is the declaration for the struct database?
Mar 5 '07 #2
Where is the declaration for the struct database?
in the start of the structure
struct database
Mar 5 '07 #3
r035198x
13,262 8TB
in the start of the structure
struct database
Oh. Your code should look something like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. struct database
  3. {
  4. char namec[6];
  5. int work_h;
  6. };
  7.  
  8.  
  9. main()
  10. {
  11. struct database[20];
  12. }
  13.  
You should read a structures tutorial.
Mar 5 '07 #4
i see thank you
Mar 5 '07 #5
but i want the structure to be inside the main
Mar 5 '07 #6
Ganon11
3,652 Expert 2GB
I don't think you can define a struct within main(), but if it is possible, I imagine it looks like:

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.    struct database {
  3.       // struct stuff here...
  4.    };
  5.    database db[20];
  6.    // operations here...
  7. }
Mar 5 '07 #7
I don't think you can define a struct within main(), but if it is possible, I imagine it looks like:

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.    struct database {
  3.       // struct stuff here...
  4.    };
  5.    database db[20];
  6.    // operations here...
  7. }
thanks alot it works
now what does the db stands for?
Mar 5 '07 #8
Ganon11
3,652 Expert 2GB
That's just the name of the array variable. You can use whatever you want/need to name the array - I used db because db = DataBase.
Mar 5 '07 #9
That's just the name of the array variable. You can use whatever you want/need to name the array - I used db because db = DataBase.
yes but why do you need another variable isnt database enough
thats what i dont understant
Mar 5 '07 #10
sicarie
4,677 Expert Mod 4TB
yes but why do you need another variable isnt database enough
thats what i dont understant
Are you talking about where he says:
database db[20];
?
Mar 5 '07 #11
Banfa
9,065 Expert Mod 8TB
im a student of c and cant get why this program keeps bringin me errors
thanks for the help
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main()
  3. {
  4.     struct database[20];
  5.     {
  6. char namec[6];
  7. int work_h;
  8.     };
  9. }
This initial code is fine without the first semicolon and correcting the definition of main.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. main()  /* main should be declared int main(int argc, char **argv)
  3. {
  4.     struct database[20];  /* <-- semi-colon here is an error */
  5.     {
  6.         char namec[6];
  7.         int work_h;
  8.     };
  9. }
Mar 5 '07 #12
Banfa
9,065 Expert Mod 8TB
I don't think you can define a struct within main(), but if it is possible, I imagine it looks like:

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.    struct database {
  3.       // struct stuff here...
  4.    };
  5.    database db[20];
  6.    // operations here...
  7. }
This is fine in a C++ environment but the title states C and in C structure names are not automatically defined so this should be

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.    struct database {
  3.       // struct stuff here...
  4.    };
  5.  
  6.    struct database db[20];
  7.    // operations here...
  8. }
However you can define the structure and declare the data in 1 statement with no problem as

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.    struct database {
  3.       // struct stuff here...
  4.    } db[20];
  5.    // operations here...
  6. }
You have also missed out the int argc and char **argv required by the most common C stanadrd in use today (C89/C90) but I will let this pass as you probably had you C++ head on.
Mar 5 '07 #13
Banfa
9,065 Expert Mod 8TB
yes but why do you need another variable isnt database enough
thats what i dont understant
In Ganons example database is not a variable name, it is the name of a structure i.e. a type name.
Mar 5 '07 #14
Ganon11
3,652 Expert 2GB
You have also missed out the int argc and char **argv required by the most common C stanadrd in use today (C89/C90) but I will let this pass as you probably had you C++ head on.
Exactly. I'm not even sure I have a C head to wear...everything about C I know, I've learned from TSDN (and overlap with C++).
Mar 5 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
4
by: Mikkel christensen | last post by:
Hi there I wonder if any of you could point me in a direction where I can find some usefull information about coding standarts. I have some generel experiense in programming but I lack many...
1
by: Chris R. | last post by:
Hi everyone. I am trying to finish my homework, but I seem not to figure out how to fix this structure that seems to make wrong output. What this program should do is use structure to save the...
5
by: Phil Kelly | last post by:
Hi I need to write the contents of a structure to a binary file - there is one string and 2 integers, but I can't seem to figure out how to write the data correctly. If I am simply writing...
5
by: Rich | last post by:
Suppose the following: typedef void (*funcptrs)(void); typedef struct { unsigned int *in; unsigned int *out; unsigned int *overrun; funcptrs myptrs; /* >=1 for ansi */ } yada;
4
by: gordon | last post by:
Hi I am still fairly new to C#.net and I sometimes make basic program design mistakes - particularyly in the context of paying attention to OOP principles. At the moment I am working on an...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
14
by: Bill Reid | last post by:
OK, let's say that have a function menu structure declaration like this (since I basically do): typedef struct function_item { char *descrip; void(*function)(void); } t_function_item; ...
25
by: jbholman | last post by:
I am pretty new to C and doing my first project in C. I actually read almost the entire FAQ, but can't seem to figure out this problem. I have a structure. I have a list of these structures. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.