Sto scrivendo un programma che chiede di popolare una struttura e mostra le informazioni inserite. C'e' un errore nel printf(), sembrano sbagliati tutti gli specificatori delle variabili definite come int e non riesco a capire come mai. Allego il codice qui sotto, grazie!
[#include <stdio.h>
/* maximum lenght of arrays */
#define MAXNUM 20
#define MAXLEN 30
#define MAXZIP 10
#define MAXBAL 20
struct info { /* set up info template */
int number [MAXNUM]; /* define an array of ints called number with max lenght 20 */
int zipcode [MAXZIP]; /* define an array of ints called zipcode with max lenght 10 */
double balance[MAXBAL]; /* define an array of doubles called balance with max lenght 20 */
double limit[MAXBAL]; /* define an array of doubles called limit with max lenght 20 */
char name [MAXLEN]; /* define an array of chars called name with max lenght 30 */
char street [MAXLEN]; /* define an array of chars called street with max lenght 30 */
char citystate [MAXLEN]; /* define an array of chars called citystate with max lenght 30 */
}; /* end of structure template */
int main (void)
{
struct info personal; /* declare personal as an info variable */
printf("Enter the account number:\n");
scanf("%d",&personal.number); /* access to the number portion */
printf("Enter your street address:\n");
while (getchar() != '\n'); /* flush stdin buffer */
gets(personal.street); /* access to the street portion */
printf("Enter your zip code:\n");
scanf("%d",&personal.zipcode); /* access to the zipcode portion */
printf("Enter city/state:\n");
while (getchar() != '\n'); /* flush stdin buffer */
gets(personal.citystate); /* access to the citystate portion */
printf("Enter the account balance:\n");
scanf("%d",&personal.balance); /* access to the balance portion */
printf("Enter the credit limit:\n");
scanf("%f",&personal.limit); /* access to the limit portion */
printf("Enter the account name:\n");
while (getchar() != '\n'); /* flush stdin buffer */
gets(personal.name); /* access to the name portion */
printf("Account number: %d \n Address: %s,%d,%s\n Account balance: %d\n Account limit: %d\n Account name: %s\n", personal.number, personal.street, personal.zipcode, personal.citystate, personal.balance, personal.limit, personal.name);
return 0;
}
]
Ultima modifica effettuata da cami il 25/08/2011 alle 0:12 |