Below code works (no errors) but I get strange output such as this from the code below:
OUTPUT:
Name is 8îk and quantity is 0
Name is ░îk and quantity is 2130567168
Where is my mistake?
#include <stdio.h>
#include <stdlib.h>
void display(struct item *);
struct item{
char name[50];
int quantity;
};
int main(void){
struct item *first = (struct item *)malloc(sizeof(struct item));
strcpy(first->name, "Banana");
first->quantity = 32;
struct item *second = (struct item *)malloc(sizeof(struct item));
strcpy(second->name, "Apple");
second->quantity = 432;
display(&first);
display(&second);
getch();
}
void display(struct item *i){
printf("Name is %10s and quantity is %7d\n", i->name, i->quantity);
}