Jump to content
labtech

Avisos ao compilar codigo no Linux (Pointers)

Recommended Posts

labtech

Eu estou a ter avisos ao compilar o seguinte codigo, o programa funciona direito. Mas dá os avisos e gostaria de saber a razão.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct aluno_str{
 char nome[20];
 struct aluno *proximo;
};
typedef struct aluno_str aluno;
aluno *raiz=NULL;
void listar(){
	 aluno *aux;
	 aux=raiz;

	 if(aux==NULL){
				 printf("Lista vazia");			
	 }else{
		 while(aux->proximo!=NULL){
				 printf("%s\n", aux->nome);
				 aux=aux->proximo;
		 }
		 printf("%s\n", aux->nome);			
	 }
}
void insereAluno(char *nome){
 aluno *aux;
 aluno *novo;
 aux=raiz;
 novo = (aluno *)malloc(sizeof(aluno));
 strcpy(novo->nome,nome);
 if (aux==NULL){
				 raiz=novo;
				 novo->proximo=NULL;
 }else{
	 novo->proximo=raiz;
	 raiz=novo;
 }
}
void insereAlunonofim(char *nome){
 aluno *aux;
 aluno *novo;
 aux=raiz;
 novo=(aluno *)malloc(sizeof(aluno));
 strcpy(novo->nome,nome);
 if (aux==NULL){
				 raiz=novo;
				 novo->proximo=NULL;
 }else{
		 while(aux->proximo!=NULL){
				 printf("%s\n", aux->nome);
				 aux=aux->proximo;
		 }
		 aux->proximo=novo;
		 novo->proximo=NULL;
 }
}
int main(){
 aluno *aux;
 char teste[20];
 insereAluno("pedro");	
 insereAluno("Maria");
 insereAluno("jose");
 insereAlunonofim("Joao Filipe");
 listar();
 }

Share this post


Link to post
Share on other sites
HappyHippyHippo

e quais os avisos ??? e em que linhas ???

de preferência, copia as linhas completas apresentadas pelo compilador


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
labtech

listaFinal.c: In function ‘listar’:

listaFinal.c:19:28: warning: assignment from incompatible pointer type [enabled by default]

listaFinal.c: In function ‘insereAluno’:

listaFinal.c:36:24: warning: assignment from incompatible pointer type [enabled by default]

listaFinal.c: In function ‘insereAlunonofim’:

listaFinal.c:53:28: warning: assignment from incompatible pointer type [enabled by default]

listaFinal.c:55:27: warning: assignment from incompatible pointer type [enabled by default]

Share this post


Link to post
Share on other sites
HappyHippyHippo
struct aluno_str{
        char nome[20];
        struct aluno *proximo; // <--- onde está definido este tipo de dados ??
};


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.