Unrecognisable error in a simple program

Discussion in 'Mac Programming' started by Quboid, May 15, 2007.

  1. Quboid macrumors 6502

    Joined:
    Oct 16, 2006
    Location:
    everywhere
    #1
    Hello all,

    I am writing a simple program (using data strcutures) to capture vowels and thier ascii equivalent from the user. I know thats too simple to be using data structures, but he point is to practice them.

    THe problem is that i am getting an error saying that i didn't declare a pointer called "nodo" (which i clearly did as the code would illustrate), maybe I made a mistake somewhere, thanks alot guys. Here's the code:

    #include<stdio.h>

    #define null 0;

    struct lista{
    char vocal;
    int ascii;
    struct lista *liga,*nodo;
    };

    struct lista *inicio;
    char voc; int ascii;
    char respuesta;
    int main()
    {
    inicio=(struct lista*)malloc(sizeof(struct lista));
    printf("\n\t introduce el voval");
    scanf("%c",&voc);
    (*inicio).vocal=voc;
    printf("\n\t Introduce el ascii para %c",voc);
    scanf("%i",&ascii);
    (*inicio).ascii=ascii;
    (*inicio).liga=null;

    do{
    nodo=(struct lista*)malloc(sizeof(struct lista));
    printf("\n\tIntroduce vocal");
    scanf("%c",&voc);
    (*nodo).vocal=voc;
    printf("\n\tintroduce el asicii para %c",voc);
    scanf("%i",&ascii);
    (*nodo).ascii=ascii;
    (*nodo).liga=inicio;
    inicio=nodo;
    printf("\n\t Quieres continuar? si(s)/no(n)");
    scanf("%c",&respuesta);
    }while(respuesta!='n');
    return 0;

    }
     
  2. SilentPanda Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #2
    Might want to wrap your code in
    Code:
     tags.
    
    You didn't ever declare nodo as a variable I don't think.  You only tried to initialize it.
    
    Nodo is part of the lista struct, not a variable by itself.
    
    [code]
    struct lista{
         char vocal;
         int ascii;
         struct lista *liga,*nodo;
    };
    
     
  3. Quboid thread starter macrumors 6502

    Joined:
    Oct 16, 2006
    Location:
    everywhere
    #3
     
  4. SilentPanda Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #4
    If you put
    Code:
     before your code and then /code (with brackets) after your code it formats nicely.
    
    Instead of:
    
    public static void main(String[] args) {
         System.out.println("Howdy");
    }
    
    You get:
    
    [code]
    public static void main(String[] args) {
         System.out.println("Howdy");
    }
    
    Makes it easier to read.
     
  5. Quboid thread starter macrumors 6502

    Joined:
    Oct 16, 2006
    Location:
    everywhere
    #5

    Thanks alot! I also see that while runnning it, it doesn't stop at the last scanf in the do/while. It just goes on to repeat, i'm looking for a logic error, but i looks fine to me.
     
  6. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #6
    Hi

    A shorter way of doing this:-

    Code:
    (*nodo).ascii=ascii;
    
    is this:-

    Code:
    nodo->ascii=ascii;
    

    b e n
     
  7. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas

Share This Page