Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Quboid

macrumors 6502
Original poster
Oct 16, 2006
441
0
everywhere
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;

}
 

SilentPanda

Moderator emeritus
Oct 8, 2002
9,992
31
The Bamboo Forest
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;
};
 

Quboid

macrumors 6502
Original poster
Oct 16, 2006
441
0
everywhere
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.[/QUOTE]

Thanks, i didn't even ntice that. What are code tags?
 

SilentPanda

Moderator emeritus
Oct 8, 2002
9,992
31
The Bamboo Forest
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.
 

Quboid

macrumors 6502
Original poster
Oct 16, 2006
441
0
everywhere
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.


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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.