How to use structures in functions which is presented in another file..


 
Thread Tools Search this Thread
Top Forums Programming How to use structures in functions which is presented in another file..
# 1  
Old 05-08-2009
How to use structures in functions which is presented in another file..

Hi ....

i m having a file called deque.c which contains structure deque and i pass the structure to function declaration push . the function push is defined in some other file .. and i added the header file also .. i list the codings below...
//deque.c
#include<stdio.h>
#include "deque.h"
#define MAX 100
#define MAX_FRONT 50
#define MAX_REAR 51
typedef struct deque
{
int element[MAX];
int front;
int rear;
};
int main()
{
int ch,ch1,ch2,ch3;
struct deque dq;
dq.front=-1;
dq.rear=101;
push(&dq,MAX_FRONT);
}

//deque.h
void push(

//deque_push.c
#include<stdio.h>
void push(struct deque *dq,int MAX_FRONT)
{
int n;
if(dq->front==MAX_FRONT)
{
printf("current postion of front: %d",dq->front);
printf("\nFront queue is full\n");
}
else
{
printf("current postion of front: %d",dq->front);
printf("\nEnter the element to insert in the front queue :");
scanf("%d",&n);
dq->front++;
dq->element[dq->front]=n;
}
}

when i compile the deque.c it will compile and shows the following warnings.
In file included from deque.c:3:
deque.h:1: warning: ‘struct deque' declared inside parameter list
deque.h:1: warning: its scope is only this definition or declaration, which is probably not what you want

deque_main.c: In function ‘main':
deque_main.c:47: warning: passing argument 1 of ‘push' from incompatible pointer type


when i compile the deque_push.c it ll shows the following error
error: dereferencing pointer to incomplete type

I request u to carify my doubts and i need the explanation for how to use the structure as parameter in a function which is presented in another file.

Thanks and Regards,
Karthik....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Modify call to functions depending on file name

Hi, I am creating a script that does gunzip/unzip/untar depending on the file extension. I have created 3 functions in my script and call them in following order. 1) gunzip function 2) unzip function 3) untar function I am using FILENAME=${FILENAME%.*} to modify filename between... (2 Replies)
Discussion started by: pinnacle
2 Replies

2. UNIX for Dummies Questions & Answers

How to perform File Functions?

I have a Student File (rno, name, marks1, marks2, marks3) How do I display a student with the highest percentage and with a percentage between 50-60. and how to sort students in ascending order as per their name (1 Reply)
Discussion started by: Ankit Saraogi
1 Replies

3. UNIX for Dummies Questions & Answers

How do I create a tar file for only dir and its subdir structures??

How do I create a tar file for only dir and its subdir structures?? (4 Replies)
Discussion started by: vx04
4 Replies

4. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

5. Shell Programming and Scripting

setter and getter functions for file manipulation with sed

Hi, I would really appreciate some help, I couldn't nail my problem: I would like to create some setter and getter functions to make my life easier. my sample file contains: keyword - some tabs - value - semicolon number 12.1; float .3; double 12; real 12.2324; stuff .234; decimal... (5 Replies)
Discussion started by: Toorop
5 Replies

6. Emergency UNIX and Linux Support

Functions defined in header / cpp file behaves different

File: A.h class A { public: struct x X; int show() { x.member_variable ? 0: -1; } }; Now if A.cpp is complied which includes A.h (which is actually in a huge project space) we see that x.member_variable value is not as expected. But if remove the show() method and place... (4 Replies)
Discussion started by: uunniixx
4 Replies

7. Linux

about system structures

hello can any1 plz tell me about the system defined structures (like sysinfo) which wil give system and n/w charecteristics (ex: freeram in sysinfo). (1 Reply)
Discussion started by: jeenat
1 Replies

8. Programming

Programming using Structures

Hi All, I was given a format of a file, and was asked to write a program which displays the data contained in the file in that purticular format. Its all so confusing. Please find the example of the format as well the code I have written in the attachment. I hope any one of u guyz can... (0 Replies)
Discussion started by: jazz
0 Replies

9. Programming

Functions use st_dev and st_inode to get the file name and directory path out?

Hi. A questions on unix sytem's directory inode and file inode. Unix have system function's that can get the following stat information out to user ( readdir, lstat.etc) struct stat { dev_t st_dev; /* device */ ino_t st_ino;... (3 Replies)
Discussion started by: nj302
3 Replies

10. Programming

reallocating structures dynamically in functions

I've recently started using structures, but I am having problems in allocating the structure dynamically. In the code below if i allocate the structure in the main program it works fine, and i get the expected output. However if i use the function rper below to increase the size of the structure i... (0 Replies)
Discussion started by: cezaryn
0 Replies
Login or Register to Ask a Question