LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2012, 10:35 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
mismatch with types in functions


Hi all, I did a little program in c language.
It works, but I have a following warning message:

Code:
prova2.c:28:6: warning: conflicting types for ‘insert’ [enabled by default]
prova2.c:15:3: note: previous implicit declaration of ‘insert’ was here
prova2.c:39:6: warning: conflicting types for ‘view’ [enabled by default]
prova2.c:16:3: note: previous implicit declaration of ‘view’ was here

The alert is in corrispondence of two functions, insert and view.
What is the problem?

The code of my program is following:

Quote:
#include <stdio.h>


#define SIZE 50


int main() {

int i, choice, dim, elem;
char c;
int vett[SIZE];

printf("Inserisci la dimensione del vettore (ricorda che deve essere un vettore di massimo 20 elementi): ");
scanf("%d", &dim);
insert(&vett, dim);
view(&vett, dim);
return 0;


}

int read(int v[], int i) {

return(v[i]);

}

void insert(int v[], int dim) {

int i;

printf("Inserisci i caratteri nel vettore:\n");
for (i=0; i<dim; i++) {
scanf("%d",&v[i]);
}

}

void view(int v[], int dim) {

int i;

for (i=0; i<dim; i++)
printf("Elemento %d del vettore: %d\n", i+1, v[i]);

}
Thank you in advance for answers.
 
Old 09-13-2012, 12:27 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by shifter View Post
Hi all, I did a little program in c language.
1) use CODE tags, not QUOTE tags when posting code.

2) pre declare functions (see bold lines in the following version of your code)
Code:
#include <stdio.h>

int read(int v[], int i);
void insert(int v[], int dim);
void view(int v[], int dim);

#define SIZE 50


int main() {

  int i, choice, dim, elem;
  char c;
  int vett[SIZE];

  printf("Inserisci la dimensione del vettore (ricorda che deve essere un vettore di massimo 20 elementi): ");
  scanf("%d", &dim);
  insert(&vett, dim);
  view(&vett, dim);
  return 0;


}

int read(int v[], int i) {

  return(v[i]);

}

void insert(int v[], int dim) {

  int i;

  printf("Inserisci i caratteri nel vettore:\n");
  for (i=0; i<dim; i++) {
    scanf("%d",&v[i]);
  }

}

void view(int v[], int dim) {

  int i;

  for (i=0; i<dim; i++)
    printf("Elemento %d del vettore: %d\n", i+1, v[i]);

}

Last edited by johnsfine; 09-13-2012 at 12:28 PM.
 
Old 09-13-2012, 12:51 PM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Ok, now it works.

Thank you very much!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Conflicting type declarations between sys/types.h and linux/types.h Da Shi Cao Programming 3 09-13-2010 11:55 PM
[C] Wrapping around functions with different return types Alien_Hominid Programming 10 02-02-2010 10:33 AM
sys/types.h & linux/types.h conflict while compiling johnnyhal Linux - Software 1 12-28-2008 06:39 PM
conflicting redeclaration of sys/types.h and linux/types.h schmil Programming 6 12-11-2008 02:02 PM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 12:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration