Error in C

Résolu/Fermé
zib@zib Messages postés 277 Date d'inscription mercredi 26 septembre 2007 Statut Membre Dernière intervention 24 juillet 2013 - 9 sept. 2009 à 19:25
zib@zib Messages postés 277 Date d'inscription mercredi 26 septembre 2007 Statut Membre Dernière intervention 24 juillet 2013 - 10 sept. 2009 à 19:53
Bonjour,
aide moi a comprendre comment se f t'il quil ya erreur sur mon code ?


il m dit que ,main must return int et malloc was not declare ..

#include <stdio.h>

void main()
{
int *p, *q;

p = (int *)malloc(sizeof(int));
q = p;
*p = 10;
printf("%d\n", *q);
*q = 20;
printf("%d\n", *q);
}

aide moi SVP

2 réponses

lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 3 567
9 sept. 2009 à 21:04
Salut,

#include <stdio.h>
#include<stdlib.h>

int main()
{
  int *p, *q;

  p = (int *)malloc(sizeof(int));
  q = p;
  *p = 10;
  printf("%d\n", *q);
  *q = 20;
  printf("%d\n", *q);
  return 0;
}

0
zib@zib Messages postés 277 Date d'inscription mercredi 26 septembre 2007 Statut Membre Dernière intervention 24 juillet 2013 5
10 sept. 2009 à 19:47
Merci Beacoup lami 20 pour votre reponse .... car sa ma beacoup aider
0
lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 3 567 > zib@zib Messages postés 277 Date d'inscription mercredi 26 septembre 2007 Statut Membre Dernière intervention 24 juillet 2013
10 sept. 2009 à 19:49
Salut,

De rien ;-)
J'espère que tu as compris ;-)

P.S. J'ai supprimé l'autre message (doublon) ;-)
0
zib@zib Messages postés 277 Date d'inscription mercredi 26 septembre 2007 Statut Membre Dernière intervention 24 juillet 2013 5
10 sept. 2009 à 19:53
Bonjour tous le monde .. j voulais savoir Pourkoi , mon code affiche l'erreur ?

or que j m'exercerce sur le forum qui donne le meme code ?


#include "stack.h"
#include <stdio.h>


/* Stack Library - This library offers the
minimal stack operations for a stack of integers */

struct stack_rec
{
stack_data data;
struct stack_rec *next;
};

struct stack_rec *top=NULL;

void stack_init()
/* Initializes this library.
Call before calling anything else. */
{
top=NULL;
}

void stack_clear()
/* Clears the stack of all entries. */
{
stack_data x;

while (!stack_empty())
x=stack_pop();
}

int stack_empty()
/* Returns 1 if the stack is empty, 0 otherwise. */
{
if (top==NULL)
return(1);
else
return(0);
}

void stack_push(stack_data d)
/* Pushes the value d onto the stack. */
{
struct stack_rec *temp;
temp=
(struct stack_rec *)malloc(sizeof(struct stack_rec));
temp->data=d;
temp->next=top;
top=temp;
}

stack_data stack_pop()
/* Returns the top element of the stack,
and removes that element.
Returns garbage if the stack is empty. */
{
struct stack_rec *temp;
stack_data d=0;
if (top!=NULL)
{
d=top->data;
temp=top;
top=top->next;
free(temp);
}
return(d);
}


aide moi S.V.P
0